如何突出显示DataGridView的特定行 [英] How to Highlight a specific Row of DataGridView

查看:87
本文介绍了如何突出显示DataGridView的特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友.

我正在VB.Net中的一个项目上工作,并且已经制作了datagridview来显示输出.
我在DataGridView中有三列.如下;
1. SerialNo
2.金额
3.日期

现在,我要突出显示其中金额"字段的值大于10,000的DataGridView行.
那么,VB.Net中有任何机制吗?

等待答案.

Dear Friends.

I am working on a project in VB.Net and I have made a datagridview to show output.
I have three columns in DataGridView. which are as under;
1. SerialNo
2. Amount
3. Date

Now, I want to Highlight Those rows of DataGridView in which the Amount Field has a value more than 10,000.
So, Is there any Mechanism in VB.Net?

Waiting for answer.

推荐答案

For Each row As DataGridViewRow In DataGridView1.Rows
            Dim val As Integer =                      Integer.Parse(row.Cells(0).Value.ToString()) 
            If val > 10000 Then
                row.DefaultCellStyle.BackColor = Color.Red
            End If
        Next

//row.Cells(1) is your Amount Column


为什么不使用:
Why not use:
For f As Integer = 0 To DataGridView1.Rows.Count - 1
Dim num As Integer = Val(DataGridView1.Rows(f).Cells(1).Value)
If num > 10000 Then
DataGridView1.Rows(f).DefaultCellStyle.BackColor = Color.Red
End If
Next


或:


Or:

For Each row As DataGridViewRow In DataGridView1.Rows
Dim num As Integer = Val(row.Cells(1).Value)
If num > 10000 Then
row.DefaultCellStyle.BackColor = Color.Red
End If
Next


这篇关于如何突出显示DataGridView的特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆