最新下载
热门教程
- 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; } }
}
}
相关文章
- 《燕云十六声》配置要求介绍 12-25
- 《燕云十六声》搬砖介绍 12-25
- 时空中的绘旅人天宇之间怎么玩 绘旅人天宇之间活动玩法介绍 12-25
- QQ2024年度报告怎么看 2024qq年度报告玩法介绍 12-25
- 归龙潮珠砂什么时候up 归龙潮红缘绮梦卡池介绍 12-25
- 王者荣耀S38赛季有什么更新 12-25