最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net WinForm下ComboBox设定SelectedValue
时间:2022-06-25 05:46:51 编辑:袖梨 来源:一聚教程网
using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.text;
using system.windows.forms;namespace winformcombobox
{
public partial class frmmain : form
{
public frmmain()
{
initializecomponent();
}
#region members
arealists ac;
public arealists gettestarea()
{
arealists al = new arealists();
for (int i = 1; i < 11; i++)
{
area a = new area();
a.area_id = i.tostring();
a.area_name = "第" + i.tostring() + "名";
al.add(a);
}
return al;
}#endregion
#region events
private void frmmain_load(object sender, eventargs e)
{
ac = gettestarea();
cblist.datasource = ac;
cblist.displaymember = "area_name";
cblist.valuemember = "area_id";
}
private void btnsetcombobox_click(object sender, eventargs e)
{
////setvalue0();
//setvaluebyvalue();
////setvaluebyitem();
setvaluebytext();}
#endregion#region methods
private void setvalue0()
{
area a = new area();
a.area_id = "8";
a.area_name = "第8名";cblist.datasource = gettestarea();
cblist.displaymember = "area_name";
cblist.valuemember = "area_id";
cblist.selectedvalue = a.area_id;
lbresult.text = cblist.selectedvalue.tostring();
}private void setvaluebyvalue()
{
area a = new area();
a.area_id = "8";
a.area_name = "第8名";cblist.selectedvalue = a.area_id;
lbresult.text = cblist.selectedvalue.gettype().tostring() + ":" + cblist.selectedvalue.tostring();
}private void setvaluebyitem()
{
area a = new area();
a.area_id = "8";
a.area_name = "第8名";cblist.selecteditem = ac.findall(delegate(area ar) { return ar.area_id == a.area_id; })[0];
lbresult.text = cblist.selecteditem.gettype().tostring() + ":" + cblist.selectedvalue.tostring();
}private void setvaluebytext()
{
area a = new area();
a.area_id = "8";
a.area_name = "第8名";cblist.selectedindex = cblist.findstring(a.area_name);
lbresult.text = cblist.selectedvalue.gettype().tostring() + ":" + cblist.selectedvalue.tostring();
}
#endregion
}
}
using system;
using system.collections.generic;
using system.text;namespace winformcombobox
{
#region area
public class area
{
private string m_area_id;
public string area_id
{
get { return m_area_id; }
set { m_area_id = value; }
}private string m_area_name;
public string area_name
{
get { return m_area_name; }
set { m_area_name = value; }
}
private double m_area_order;
public double area_order
{
get { return m_area_order; }
set { m_area_order = value; }
}
}
#endregion[serializable]
public class arealists : list
{
private int _maxitems = 0;
public int maxitems { get { return this._maxitems; } set { this._maxitems = value; } }
}
}
相关文章
- 人们熟悉的寄居蟹属于以下哪种分类 神奇海洋11月21日答案 11-21
- 第五人格11.22共研服有什么更新 11月22日共研服更新内容介绍 11-21
- 原神恰斯卡怎么培养 11-21
- 无期迷途四星装束是谁 11-21
- 王者荣耀帝丹高中校服怎么获得 11-21
- 光遇姆明季后续版本怎么玩 11-21