vb.net的datagridview如何让表格根据表格数据来改变颜色,如值为1时表格为红色,2时为蓝色
Private Sub Form1_Load(sender As Object,e As EventArgs) Handles MyBase.Load Dim 数据表 As New DataSet() 数据表.Tables.Add() Dim aa As DataTable = 数据表.Tables(0) aa.Columns.Add("lb") aa.Rows.Add("a") aa.Rows.Add("b") Dim biaoge As DataGridView = New DataGridView biaoge.Parent = Me biaoge.Location = New Point(10,46) biaoge.DataSource = aa TextBox1.Text = biaoge.ColumnCount.ToString + "列" TextBox1.Text += " " + biaoge.Columns.Count.ToString 表格控件颜色控制(biaoge,1) End Sub Sub 表格控件颜色控制(表格控件 As DataGridView,参数 As Int16) Dim 行数 As Int16 = 表格控件.Rows.Count - 1 Do '表格控件.Rows(行数).DefaultCellStyle.BackColor = IIf(参数 = 行数 Mod 2,Color.AliceBlue,Color.Beige) 表格控件.Rows(行数).Cells(0).Style.BackColor = IIf(参数 = 行数 Mod 2,Color.Beige) 行数 -= 1 Loop While (行数 >= 0) End Sub原文链接:https://www.f2er.com/vb/257493.html