.net - DataGridView 的特定格式
问题描述
我正在尝试在格式化 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
并将该颜色更改为浅蓝色,如图所示。图片
我可能在某个地方搞砸了我的代码,但我的 VS 有一个错误,它会停止并让应用程序中断,但它不会向我显示异常。
有人知道我可以从这里做些什么来修复它吗?
解决方案
Lokks 好的,你在行循环中错过了一个目标 = 目标 - 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
推荐阅读
- bash - 为什么我的 echo 命令会在彼此上写两个单词?
- r - 计算R中所有列组合的类内系数
- c++ - 在花括号内添加语句会更改代码功能?
- python - 无法点击地图上的标志
- android - 从 uri 下载歌曲并将其存储在应用程序特定的文件夹中
- javascript - Jquery/Javascript:如何删除当前页面中未使用的页面的 JS 文件
- jquery - 使用 AJAX 错误停止表单重定向
- c# - User.Identity.Name 在 ASP.NET Core MVC 应用程序中返回 null
- css - 为什么 align: center in parent 会弄乱我的位置:绝对叠加?
- hash - 如何应用统一散列函数?