如何中止取消选中已检查列表框中的项目?
我有一个方法:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将列设为只读并那么你就不必费力去阻止它被改变。
否则,订阅
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 sete.Cancel = true
.