我是.net的初学者。
我需要在CheckedListBox中显示一些记录。
我在DataSet中有表(Cat):
我需要在CheckedListBox控件中显示数据表(颜色列)的内容。
怎么能实现呢?
它似乎是CheckedListBox does not support binding,所以这不会按预期工作:
CheckedListBox1.DataSource = tempDataSet.Tables("Cat")
CheckedListBox1.DisplayMember = "Color"
CheckedListBox1.ValueMember = "ID"
您可以使用Bindable CheckedListBox代替。然后,您可以使用“属性”窗口在设计时绑定:
你可以点击这个链接:
how to bind data in checkedlistbox in window application
或尝试此模板:
SqlDataAdapter da = new SqlDataAdapter("SELECT NAME AC_CODE FROM AccountM where compcode='" + Compcls.Gcomp_cd + "'", con);
DataSet ds = new DataSet();
da.Fill(ds, "AccountM ");
checkedListBox1.DataSource = ds;
checkedListBox1.SelectedValue = "AC_CODE";
checkedListBox1.SelectedItem = "NAME";
假设您将checkedListBox1.SelectedValu
e保存在db中,您可以执行以下操作:
myDt
希望这可以帮助...