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
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.