从数据库DevExpress CheckedListBoxControl获取项目索引 [英] Get item index from databound DevExpress CheckedListBoxControl

查看:1021
本文介绍了从数据库DevExpress CheckedListBoxControl获取项目索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 CheckedListBoxControl 中找到特定值的索引。 CheckedListBoxControl具有DataSource,DisplayMember,ValueMember容易设置为DataTable和两列。现在我必须将CheckedState属性设置为true,方法是通过使用ValueMember中的某些值从CheckedListBoxControl中找到它的索引,然后调用 SetItemChecked()方法与该索引。

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.

推荐答案

如果列表框控件绑定到数据源,则可以使用 GetItem()方法和ItemCount属性:

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);
}

要查找指定项目的索引,您可以使用 FindItem()方法

由DisplayText搜索:

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);
});

ValueMember搜索:

searching by ValueMember:

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

另请参阅如何获取检查的数据绑定CheckedListBoxControl的行文章。

这篇关于从数据库DevExpress CheckedListBoxControl获取项目索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆