如果药物已经过期,我已经更改了datagridview中行的背景颜色?

问题描述 投票:-1回答:2

如果药物已经过期,我已经更改了datagridview中行的背景颜色?

        con.Open()
        Dim query As String
        query = "Select product_code,drug_name,quantity,expiration_date from medicine where expiration_date"
        command = New MySqlCommand(query, con)
        readers = command.ExecuteReader

        Dim count As Integer
        count = 0
        While readers.Read
            count = count + 1
        End While
        con.Close()
        If count = 0 Then
            MsgBox("no expiration")
        Else
            Dim SQL As String = ""
            Dim da As MySqlDataAdapter = Nothing
            Dim dt As New DataTable
            SQL = "Select product_code,drug_name,quantity,expiration_date from medicine where expiration_date"
            command = New MySqlCommand(SQL, con)
        End If
vb.net
2个回答
0
投票

好的拳头你需要用这种方式加载de grid与数据库数据:

    con.Open()
        Dim query As String
        Dim da As new MySqlDataAdapter
        Dim dt As New DataTable
        query = "Select product_code,drug_name,quantity,expiration_date from medicine where expiration_date is not null"
        command = New MySqlCommand(query, con)
        da.SelectCommand = cm
        da.Fill(dt)
        dgv1.datasource = dt

然后你必须在cellformating事件中设置颜色:

 Private Sub dgv1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles dgv1.CellFormatting
        If dgv1.Rows(e.RowIndex).Cells("expiration_date").Value < now Then
            dgv1.Rows(e.RowIndex).cells("expiration_date").Style.BackColor = Color.Red
        End If


0
投票

我不明白你要做什么或者你将如何加载网格。任何改变列颜色的方法都是:

           dgv1.Columns("columnsName").DefaultCellStyle.BackColor = Color.Red
© www.soinside.com 2019 - 2024. All rights reserved.