【问题标题】:Not allow selection of a certain column in a DataGridView control不允许在 DataGridView 控件中选择特定列
【发布时间】:2018-02-25 02:41:32
【问题描述】:

我有这个数据网格视图

我想知道是否有办法禁止用户选择第一列的单元格(带有箭头的单元格),但我仍然需要用户能够选择所有其他单元格,除了第一列。

【问题讨论】:

    标签: vb.net winforms datagridview


    【解决方案1】:

    如果选择移动到目标列,使用DataGridView1.SelectionChanged 事件可以阻止选择焦点,将DataGridView1.CurrentCell 设置为同一行中的下一列单元格。

    这适用于鼠标点击和光标移动产生的选择事件。

    Private blockedColumn As Integer = 0
    
    Private Sub DataGridView1_SelectionChanged(sender As Object, e As EventArgs) Handles DataGridView1.SelectionChanged
        If DataGridView1.CurrentCell.ColumnIndex = blockedColumn Then
            DataGridView1.CurrentCell = 
                DataGridView1(blockedColumn + 1, DataGridView1.CurrentCell.RowIndex)
        End If
    End Sub
    

    您可以设置dataGridView1.Columns(0).Frozen = True 用于其他用途。不过没必要。

    【讨论】:

      猜你喜欢
      • 2012-12-18
      • 1970-01-01
      • 2012-06-13
      • 2012-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-07
      相关资源
      最近更新 更多