如何在CheckedListBox中显示一些记录

问题描述 投票:2回答:3

我是.net的初学者。

我需要在CheckedListBox中显示一些记录。

我在DataSet中有表(Cat):

我需要在CheckedListBox控件中显示数据表(颜色列)的内容。

怎么能实现呢?

c# .net winforms
3个回答
1
投票

它似乎是CheckedListBox does not support binding,所以这不会按预期工作:

CheckedListBox1.DataSource = tempDataSet.Tables("Cat")
CheckedListBox1.DisplayMember = "Color"
CheckedListBox1.ValueMember = "ID"

您可以使用Bindable CheckedListBox代替。然后,您可以使用“属性”窗口在设计时绑定:


1
投票

你可以点击这个链接:

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";

0
投票

假设您将checkedListBox1.SelectedValue保存在db中,您可以执行以下操作:

  1. 将数据加载到数据表中,例如myDt
  2. 循环数据表中的每个数据行,并根据qazxsw poi值设置检查状态 qazxsw poi

希望这可以帮助...

© www.soinside.com 2019 - 2024. All rights reserved.