我正在尝试在格式化DataGridView方面复制类似的程序。
这就是我想要的样子:
我已经尝试过:
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
' Initial Styling of Cell Selection
For i As Integer = 0 To DataGridView1.Rows.Count - 1
For j As Integer = 0 To DataGridView1.Columns.Count - 1
DataGridView1.Rows(i).Cells(j).Style.BackColor = Color.FromKnownColor(KnownColor.Control)
Next
Next
Dim current As Integer = 0
current = DataGridView1.SelectedCells(0).ColumnIndex
Dim target As Integer = current
Dim looping As Boolean = True
While looping
If target = 0 Then
looping = False
End If
DataGridView1.SelectedRows(0).Cells(target).Style.BackColor = Color.Orange
target = target - 1
End While
current = DataGridView1.SelectedRows(0).Index
target = current
Dim column As Integer = DataGridView1.SelectedCells(0).ColumnIndex
looping = True
While looping
If target = 0 Then
looping = False
End If
DataGridView1.SelectedRows(target).Cells(column).Style.BackColor = Color.Orange
End While
End Sub
我还将选择模式设置为CellSelect
,并将该颜色更改为浅蓝色,如该图片所示。 Image
我可能已经在某个地方搞砸了我的代码,但是我的VS有一个错误,它将停止并导致应用程序中断,但不会向我显示异常。
有人有什么想法我可以从这里做些什么来解决它?
答案 0 :(得分:0)
好吧,好吧,您错过了一个target = target-行循环中有1个
target = current
Dim column As Integer = DataGridView1.SelectedCells(0).ColumnIndex
looping = True
While looping
If target = 0 Then
looping = False
End If
DataGridView1.SelectedRows(target).Cells(column).Style.BackColor = Color.Orange
target -= 1
End While