使用数据源用的CheckBoxList [英] Using datasource with CheckBoxList

查看:155
本文介绍了使用数据源用的CheckBoxList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows窗体应用程序使用的CheckBoxList,我试图申请一个数据源吧。

I use CheckBoxList in my Windows Forms application and am trying to apply a datasource for it.

有一个数据表,DT,与列 ID 名称器isChecked ,我用这样的代码:

Having a DataTable, 'dt', with columns id, name and ischecked, I use such code:

((ListBox)MyCheckBoxList).DataSource = dt;
((ListBox)MyCheckBoxList).DisplayMember = "name";
((ListBox)MyCheckBoxList).ValueMember = "id";



如何设置CheckState在MyCheckBoxList所有项目?

How do I set CheckState for all items in MyCheckBoxList?

我把这个值在我的数据表,并希望他们MyCheckBoxList链接。

I keep this value in my datatable and want to link them with MyCheckBoxList.

推荐答案

我已经决定我的问题在两个步骤。首先,我采用的数据源,然后在圈内设置Checked属性像下面的代码的每个项目:

I've decided my problem in two steps. First, I applied the datasource, and then in circle set the Checked property for each item like in the following code:

((ListBox)MyCheckBoxList).DataSource = dt;
((ListBox)MyCheckBoxList).DisplayMember = "name";
                    ...

for (int i = 0; i < folloving.Items.Count; i++ )
{
    DataRowView row = (DataRowView)MyCheckBoxList.Items[i];
    bool isChecked = Convert.ToBoolean(row["checked"]);
    MyCheckBoxList.SetItemChecked(i, isChecked);
}

这篇关于使用数据源用的CheckBoxList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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