checkboxlistcontrol使用
checkedListBoxControl1使用和listbox等控件相似,但还是有些区别的
1.绑定值:
List<CategoryInfo> modelList = new List<CategoryInfo>();
foreach (string str in result)
{
string[] modelStr = str.Split('-');
modelList.Add(new CategoryInfo() { ID = modelStr[0], Title = modelStr[1] });
}
checkedListBoxControl1.ValueMember = "";
checkedListBoxControl1.DisplayMember = "";
checkedListBoxControl1.DataSource = modelList;
foreach (string str in result)
{
string[] modelStr = str.Split('-');
modelList.Add(new CategoryInfo() { ID = modelStr[0], Title = modelStr[1] });
}
checkedListBoxControl1.ValueMember = "";
checkedListBoxControl1.DisplayMember = "";
checkedListBoxControl1.DataSource = modelList;
2.取值:
因为使用datasource绑定的值,所以checkedListBoxControl1.items.cout是0.取不到值的,只能用下面的方法来获取
int i = 0;
while (checkedListBoxControl1.GetItemValue(i) != null)
{
if (checkedListBoxControl1.GetItemChecked(i) == true)
{
CheckBook.Add((checkedListBoxControl1.GetItem(i) as CategoryInfo));
}
i++;
}
while (checkedListBoxControl1.GetItemValue(i) != null)
{
if (checkedListBoxControl1.GetItemChecked(i) == true)
{
CheckBook.Add((checkedListBoxControl1.GetItem(i) as CategoryInfo));
}
i++;
}
-------此处无银三百两------