如何在checkedlistbox中止取消选中项目?

时间:2011-06-04 19:03:02

标签: c# winforms checkedlistbox

我有一个方法:

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”不应该被取消检查,所以我想要取消对该项目的取消检查。

也许在checkedlistbox上有一些事件?

祝你好运

1 个答案:

答案 0 :(得分:0)

制作专栏read-only,然后您无需防止其被改变。

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