以编程方式选择 winforms 复选框列表中的项目

发布于 2024-09-29 04:55:10 字数 459 浏览 4 评论 0原文

我不知道如何以编程方式选择复选框列表中的项目。

这种方法无法编译,但我想向您展示我想要得到的结果。

public ColumnsSelector(Dictionary<string, bool> dataPropertyNames)
            : this()
        {
            foreach (var item in dataPropertyNames)
            {
                checkedListBox1.Items.Add(item.Key);
                checkedListBox1.Items[checkedListBox1.Items.IndexOf(item.Key)].Checked = item.Value;
            }
        }

你如何强制解决这个问题?

I can't figure out how to programmatically select items in checkboxlist.

This method of cource doesn't compile, but I want to show you what a result I want to get.

public ColumnsSelector(Dictionary<string, bool> dataPropertyNames)
            : this()
        {
            foreach (var item in dataPropertyNames)
            {
                checkedListBox1.Items.Add(item.Key);
                checkedListBox1.Items[checkedListBox1.Items.IndexOf(item.Key)].Checked = item.Value;
            }
        }

How do you force with this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

手长情犹 2024-10-06 04:55:10

使用 CheckedListBox.SetItemCheckState

checkedListBox.SetItemCheckState(checkedListBox1.Items.Count - 1, CheckedState.Checked);

有效对于已检查、未检查和不确定。您还可以使用 CheckedListBox.SetItemChecked :

checkedListBox.SetItemChecked(checkedListBox1.Items.Count - 1, true);

Use CheckedListBox.SetItemCheckState:

checkedListBox.SetItemCheckState(checkedListBox1.Items.Count - 1, CheckedState.Checked);

which works for checked, unchecked, and indeterminate. You can also use CheckedListBox.SetItemChecked:

checkedListBox.SetItemChecked(checkedListBox1.Items.Count - 1, true);
丘比特射中我 2024-10-06 04:55:10
 checkedListBox1.Items.Add(item.Key);
 checkedListBox1.SetItemChecked(checkedListBox1.Items.Count - 1, item.Value);

或者只是

 checkedListBox1.Items.Add(item.Key, item.Value);
 checkedListBox1.Items.Add(item.Key);
 checkedListBox1.SetItemChecked(checkedListBox1.Items.Count - 1, item.Value);

or just

 checkedListBox1.Items.Add(item.Key, item.Value);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文