vb.net – 根据单元格值的数量更改DataGridView中的行颜色
发布时间:2020-12-17 00:20:09 所属栏目:大数据 来源:网络整理
导读:我需要在datagridview中更改行的颜色,但我的代码对我不起作用. 我总是收到一个错误,上面写着“名为Quantity的列:无法找到.参数名称:columnName” 这是我的代码: Private Sub DataGridView1_CellFormatting(ByVal sender As Object,ByVal e As DataGridVie
我需要在datagridview中更改行的颜色,但我的代码对我不起作用.
我总是收到一个错误,上面写着“名为Quantity的列:无法找到.参数名称:columnName” 这是我的代码: Private Sub DataGridView1_CellFormatting(ByVal sender As Object,ByVal e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting For i As Integer = 0 To Me.DataGridView1.Rows.Count - 1 If Me.DataGridView1.Rows(i).Cells("Quantity:").Value < 5 Then Me.DataGridView1.Rows(i).Cells("Quantity:").Style.ForeColor = Color.Red End If Next End Sub 请帮我解决一下.谢谢.
这可能会有所帮助
>使用“RowPostPaint”事件 我从C#转换了这个(‘从:http://www.dotnetpools.com/Article/ArticleDetiail/?articleId=74) Private Sub dgv_EmployeeTraining_RowPostPaint(sender As Object,e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dgv_EmployeeTraining.RowPostPaint If e.RowIndex < Me.dgv_EmployeeTraining.RowCount - 1 Then Dim dgvRow As DataGridViewRow = Me.dgv_EmployeeTraining.Rows(e.RowIndex) '<== This is the header Name 'If CInt(dgvRow.Cells("EmployeeStatus_Training_e26").Value) <> 2 Then '<== But this is the name assigned to it in the properties of the control If CInt(dgvRow.Cells("DataGridViewTextBoxColumn15").Value.ToString) <> 2 Then dgvRow.DefaultCellStyle.BackColor = Color.FromArgb(236,236,255) Else dgvRow.DefaultCellStyle.BackColor = Color.LightPink End If End If End Sub (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |