【发布时间】:2019-02-24 17:34:22
【问题描述】:
我正在尝试在格式化 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 有一个错误,它会停止并让应用程序中断,但它不会向我显示异常。
有人知道我可以从这里做些什么来解决它吗?
【问题讨论】:
-
调试你的代码。设置断点并逐行执行代码并检查其行为是否符合您的预期。如果您还没有调试,那么在这里发布还为时过早。如果您已经调试过,那么您可以在此处提供更具体的信息。
标签: .net vb.net winforms datagridview