Get item index from databound DevExpress CheckedListBoxControl

可紊 提交于 2019-12-02 00:09:22

问题


I am trying to find the index of a particular value from the CheckedListBoxControl. The CheckedListBoxControl has a DataSource, DisplayMember, ValueMember set to a DataTable and two columns receptively. Now I have to set the CheckedState Property to true by finding its index from CheckedListBoxControl by using some value from the ValueMember and then calling the SetItemChecked() method with that index.

I'm not able to find any property or method which returns the index. Please help.


回答1:


If a list box control is bound to a data source, you can iterate throught all listbox items using the the GetItem() method and the ItemCount property:

for(int i = 0; i < checkedListBoxControl.ItemCount; i++) {
    object dataRow = checkedListBoxControl.GetItem(i);
}

To find the index of the specified item you can use the FindItem() method
searching by DisplayText:

string s = "searchString";
int index = checkedListBoxControl.FindItem(startIndex, true, delegate(ListBoxFindItemArgs e) {
   e.IsFound = s.Equals(e.DisplayText);
});

searching by ValueMember:

object value = 100;
int index = checkedListBoxControl.FindItem(startIndex, true, delegate(ListBoxFindItemArgs e) {
   e.IsFound = object.Equals(value, e.ItemValue);
});

Please also take a look at the "How to get checked rows of a data-bound CheckedListBoxControl" article.



来源:https://stackoverflow.com/questions/9003193/get-item-index-from-databound-devexpress-checkedlistboxcontrol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!