【问题标题】:Set datagridview rowcount to max 1将 datagridview 行数设置为最大 1
【发布时间】:2023-03-04 21:16:01
【问题描述】:

伙计们,我想将 datagridview 设置为只接受一行,但我很难做到这一点。 表示在第一行之后不允许用户添加新行。 所以 datagridview 总是只有一行。虽然在 Visual Basic 中 任何帮助将不胜感激。

【问题讨论】:

    标签: visual-studio-2010 datagridview


    【解决方案1】:
    Private Sub Datagridview1_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DatagridviewCellCancelEventArgs) Handles DataGridView.CellBeginEdit
    
        For Each r As DataGridViewRow in DataGridView1.Rows
    
       If r.IsNewRow AndAlso DataGridView1.CurrentRow.Index = 0
           e.Cancel = False
         Else
         e.Cancel = True
          End If
    Next
    
     End Sub
    

    【讨论】:

      猜你喜欢
      • 2018-02-19
      • 2019-03-19
      • 2018-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多