如何中止取消选中已检查列表框中的项目?

发布于 2024-11-13 22:03:18 字数 2038 浏览 4 评论 0原文

我有一个方法:

foreach (DataGridViewColumn column in dgvGeoObjectsFirstView.Columns)
            {
                geoObjectsColumnsCheckedListBoxFirstView.Items.Add(column.HeaderText, column.Visible);
                geoObjectsColumnsCheckedListBoxFirstView.ItemCheck += (ss, ee) =>
                {
                    if (geoObjectsColumnsCheckedListBoxFirstView.SelectedItem != "Show")
                    {
                        if (geoObjectsColumnsCheckedListBoxFirstView.SelectedItem != null)
                        {
                            var selectedItem = geoObjectsColumnsCheckedListBoxFirstView.SelectedItem.ToString();

                            foreach (DataGridViewColumn column2 in dgvGeoObjectsFirstView.Columns)
                            {
                                if (column2.HeaderText == selectedItem.ToString())
                                {
                                    column2.Visible = ee.NewValue == CheckState.Checked;
                                }
                            }
                            int currentDisplayIndex = 0;

                            foreach (DataGridViewColumn dataGridViewColumn in dgvGeoObjectsFirstView.Columns)
                            {
                                if (dataGridViewColumn.HeaderText == selectedItem)
                                {
                                    currentDisplayIndex = dataGridViewColumn.Index;
                                }
                            }



                            int futureDisplayIndex = geoObjectsColumnsCheckedListBoxFirstView.SelectedIndex;

                            PassColumnsInFirstView(futureDisplayIndex, currentDisplayIndex);
                        }
                    }
                    else
                    {
      //What can I do here to have item checked
                    }
                };
            }\

问题是其中一列的标题文本“Show”不应该是不可选中的,所以我想要类似中止取消选中该项目的操作。

也许checklistbox 上有一些事件?

此致

I have a method:

foreach (DataGridViewColumn column in dgvGeoObjectsFirstView.Columns)
            {
                geoObjectsColumnsCheckedListBoxFirstView.Items.Add(column.HeaderText, column.Visible);
                geoObjectsColumnsCheckedListBoxFirstView.ItemCheck += (ss, ee) =>
                {
                    if (geoObjectsColumnsCheckedListBoxFirstView.SelectedItem != "Show")
                    {
                        if (geoObjectsColumnsCheckedListBoxFirstView.SelectedItem != null)
                        {
                            var selectedItem = geoObjectsColumnsCheckedListBoxFirstView.SelectedItem.ToString();

                            foreach (DataGridViewColumn column2 in dgvGeoObjectsFirstView.Columns)
                            {
                                if (column2.HeaderText == selectedItem.ToString())
                                {
                                    column2.Visible = ee.NewValue == CheckState.Checked;
                                }
                            }
                            int currentDisplayIndex = 0;

                            foreach (DataGridViewColumn dataGridViewColumn in dgvGeoObjectsFirstView.Columns)
                            {
                                if (dataGridViewColumn.HeaderText == selectedItem)
                                {
                                    currentDisplayIndex = dataGridViewColumn.Index;
                                }
                            }



                            int futureDisplayIndex = geoObjectsColumnsCheckedListBoxFirstView.SelectedIndex;

                            PassColumnsInFirstView(futureDisplayIndex, currentDisplayIndex);
                        }
                    }
                    else
                    {
      //What can I do here to have item checked
                    }
                };
            }\

The problem is taht one column which header text "Show" shouldn't be uncheckable, so I want something like aborting unchecking for this item.

Maybe some event on checkedlistbox?

Best regards

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

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

发布评论

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

评论(1

你好,陌生人 2024-11-20 22:03:18

将列设为只读并那么你就不必费力去阻止它被改变。

否则,订阅 CellEndEdit 事件并设置 e.Cancel = true

Make the column read-only and then you needn't fiddle with preventing it from being changed.

Otherwise, subscribe to the CellEndEdit event and set e.Cancel = true.

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