WinForm常用的几个控件的简单使用方法
2013-01-10 14:21
309 查看
comboBox控件数据绑定:
思想:从数据库获取数据,转化成List类型,逐一添加
参考代码:
List<QinFonCms.Model.T_Plant_Category> lst2 = new QinFonCms.BLL.T_Plant_Category().GetList(string.Format("TypeID={0} and Level={1} order by {2}", 20, 1,"Name"));
if (lst2.Count > 0)
{
comboBox_Phylum.Items.Clear();
foreach (QinFonCms.Model.T_Plant_Category item in lst2)
{
comboBox_Phylum.Items.Add(new ListItem(item.Name, item.ID.ToString()));
}
}
comboBox控件实现默认选中项
首先实现默认选中项,必须想绑定数据源,就以上一例所绑定的数据源为标准,实现默认选中。循环获取每个项,当所需选中的项的value值与所项的value值相等,设置空间的SelectedIndex为当前项的索引。(这里所需选中的项的值为model.PhylumID.ToString())
参考代码:
for (int j = 0; j < comboBox_Phylum.Items.Count; j++)
{
if (((ListItem)comboBox_Phylum.Items[j]).Value == model.PhylumID.ToString())
{
comboBox_Phylum.SelectedIndex = j;
}
}
checkedListBox空间的数据绑定方法:
思想:从数据库获取数据,转化成List类型,逐一添加
List<QinFonCms.Model.T_Plant_Category> lst2 = new QinFonCms.BLL.T_Plant_Category().GetList(string.Format("TypeID={0} and Level={1} order by {2}", 20, 1,"Name"));
if (lst2.Count > 0)
{
checkedListBox1.Items.Clear();
foreach (QinFonCms.Model.T_Plant_Category item in lst2)
{
checkedListBox1.Items.Add(new ListItem(item.Name, item.ID.ToString()));
}
}
checkedListBox控件设置默认选中项:
for (int j = 0; j < checkedListBox1.Items.Count; j++)
{
if (((ListItem)checkedListBox1.Items[j]).Value != "")
{
if (((ListItem)checkedListBox1.Items[j]).Value == model.PhylumID.ToString())
{
checkedListBox1.SetItemChecked(j,true);
}
}
}
思想:从数据库获取数据,转化成List类型,逐一添加
参考代码:
List<QinFonCms.Model.T_Plant_Category> lst2 = new QinFonCms.BLL.T_Plant_Category().GetList(string.Format("TypeID={0} and Level={1} order by {2}", 20, 1,"Name"));
if (lst2.Count > 0)
{
comboBox_Phylum.Items.Clear();
foreach (QinFonCms.Model.T_Plant_Category item in lst2)
{
comboBox_Phylum.Items.Add(new ListItem(item.Name, item.ID.ToString()));
}
}
comboBox控件实现默认选中项
首先实现默认选中项,必须想绑定数据源,就以上一例所绑定的数据源为标准,实现默认选中。循环获取每个项,当所需选中的项的value值与所项的value值相等,设置空间的SelectedIndex为当前项的索引。(这里所需选中的项的值为model.PhylumID.ToString())
参考代码:
for (int j = 0; j < comboBox_Phylum.Items.Count; j++)
{
if (((ListItem)comboBox_Phylum.Items[j]).Value == model.PhylumID.ToString())
{
comboBox_Phylum.SelectedIndex = j;
}
}
checkedListBox空间的数据绑定方法:
思想:从数据库获取数据,转化成List类型,逐一添加
List<QinFonCms.Model.T_Plant_Category> lst2 = new QinFonCms.BLL.T_Plant_Category().GetList(string.Format("TypeID={0} and Level={1} order by {2}", 20, 1,"Name"));
if (lst2.Count > 0)
{
checkedListBox1.Items.Clear();
foreach (QinFonCms.Model.T_Plant_Category item in lst2)
{
checkedListBox1.Items.Add(new ListItem(item.Name, item.ID.ToString()));
}
}
checkedListBox控件设置默认选中项:
for (int j = 0; j < checkedListBox1.Items.Count; j++)
{
if (((ListItem)checkedListBox1.Items[j]).Value != "")
{
if (((ListItem)checkedListBox1.Items[j]).Value == model.PhylumID.ToString())
{
checkedListBox1.SetItemChecked(j,true);
}
}
}
相关文章推荐
- cocos2d-x-2.0新增加了几个UI控件,这里我介绍下常用的这几个UI控件(CCControlSlider、CCControlSwitch、CCControlColourPicker)使用方法
- cocos2d-x-2.0新增加了几个UI控件,这里我介绍下常用的这几个UI控件(CCControlSlider、CCControlSwitch、CCControlColourPicker)使用方法
- cocos2d-x-2.0新增加了几个UI控件,这里我介绍下常用的这几个UI控件(CCControlSlider、CCControlSwitch、CCControlColourPicker)使用方法
- 常用WEB控件使用的几个注意点
- 2009-04-09技术学习:wicket常用控件使用方法
- Android 第五课 常用控件的使用方法(TextView、Button、EditView、 ImageView、 ProgressBar、 ProgressDialog等)
- 【转载于百度空间】C# WinForm中的BackgroundWorker控件的使用方法
- C# Winform 跨线程更新UI控件常用方法汇总
- C++ double转string类型以及MFC控件简单使用方法
- C# Winform 跨线程更新UI控件常用方法总结(转)
- C#|Winform编程中文本框控件的常用方法
- C# Winform 跨线程更新UI控件常用方法汇总
- 回调函数中使用MFC类的成员或对话框控件的简单方法
- Qt第三方图形控件qwt的编译安装与使用的简单方法(Win7+Qt4.8.6+MinGW4.8.2)
- [转]ListView控件中几个常用的扩展方法
- 常用控件的使用方法--(TextView/EditText/Button/Menu) -计算器代码
- C#WinForm程序最小化后在托盘中隐藏方法以及几个关键点的简单分析
- VC 6.0常用控件使用方法介绍
- 常用控件的使用方法-2
- winform中ComboBox控件的简单使用