我已经将数据从数据库加载到datagridview并且具有两列目标值和体积,其中项目单位>项目最小值,该体积单元格应该是绿色并且项目min<项目单位然后音量应为红色。我尝试了但是我无法做到。
导入System.Data.SqlClient
Public Class view_all
Dim con1 As SqlConnection
Dim con As String
Dim da As SqlDataAdapter
Dim ds As DataSet
Private Sub view_all_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim obj As New config
con1 = New SqlConnection
con1 = obj.getcontion()
con1.Open()
da = New SqlDataAdapter("select * from item", con1)
ds = New DataSet
da.Fill(ds, "item")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "item"
DataGridView1.Columns(0).HeaderText = "Item Id"
DataGridView1.Columns(1).HeaderText = "Item Name"
DataGridView1.Columns(2).HeaderText = "Item Number"
DataGridView1.Columns(3).HeaderText = "Item Propose"
DataGridView1.Columns(4).HeaderText = "Item Unit "
DataGridView1.Columns(5).HeaderText = "Item Max"
DataGridView1.Columns(6).HeaderText = "Item min"
End Sub
答案 0 :(得分:0)
所以你需要做的是获取列索引,然后遍历所有行,这意味着遍历指定列中的所有单元格。
Dim intR As Integer = Maintt.DataGridView1.RowCount - 1
Dim jr as integer ' for the rows
For jR = 1 To intR
'Put condition here
Maintt.DataGridView1.Item(4, jR).Style.BackColor = Color.LightGreen
Next
这将适用于您的第4列 现在,您已将此列中的所有单元格置于绿色条件下。 再次浏览此列,找到背景为绿色的单元格, 获取行索引并将此行中的所有单元格设置为绿色。