0
我不希望用户能够选择行。 [selectionmode = none].net DataGridView以编程方式只选择
无论如何,我的应用程序需要选择datagridview中的行来突出显示它们。 [=的SelectionMode没有将无法工作,那么] [能使用=假]
而且用户必须能够在DataGridView滚动[启用= false将不会工作,那么,以及]
有一种方法来实现这一点?
我不希望用户能够选择行。 [selectionmode = none].net DataGridView以编程方式只选择
无论如何,我的应用程序需要选择datagridview中的行来突出显示它们。 [=的SelectionMode没有将无法工作,那么] [能使用=假]
而且用户必须能够在DataGridView滚动[启用= false将不会工作,那么,以及]
有一种方法来实现这一点?
使用.ReadOnly
而不是.Enabled
属性来启用滚动条。
然后,您可以使用CellFormatting
事件突出显示单元格和SelectionChanged
事件以禁用用户选择。
Private Sub DataGridView1_CellFormatting(sender As Object, e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
If e.RowIndex Mod 2 = 0 Then
e.CellStyle.BackColor = Color.Green
ElseIf Me.DataGridView1.Rows(e.RowIndex).Cells("YourTestField").Value = "YourValue" Then
e.CellStyle.BackColor = Color.Orange
End If
End Sub
Private Sub DataGridView1_SelectionChanged(sender As Object, e As System.EventArgs) Handles DataGridView1.SelectionChanged
Me.DataGridView1.ClearSelection()
End Sub