如何用绿色填充datagridview中的选定行? [英] how to fill selected rows in datagridview with green colour?

查看:80
本文介绍了如何用绿色填充datagridview中的选定行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有1列命名为日期。



但是有些行是空白的,有些行在datagridview中填充了日期



现在我想将日期的空白行颜色为绿色,填充日期行为红色。



我该怎么办?



我写的条件是什么?



请有人帮帮我



提前感谢。



i将非常有责任

i have 1 column named as date.

but some rows are blank and some rows are filled with date in datagridview

now i want to colour the blank rows of date as green and filled date rows as red.

how do i do that?

what is the condition that i will write?

please can anyone help me

thanks in advance.

i will be very obliged

推荐答案

Hi Sudeshna,
Here i am giving you the code for your problem.
So do as you have done adding the data to the datagrid view. Now add these code for evaluation of the rowdata and its values for coloring.

<code>Dim i As Integer
        For i = 0 To DataGridView1.Rows.Count - 1
            If IsNothing(DataGridView1.Rows(i).Cells(0).Value) Then
                DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.Green
            Else
                DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.Red
            End If
        Next</code>
here the cells(0) refers to the column where the date data is entered. I think it will solve your problem.
Thank you


For Each rw As GridViewRow In dgrd_WWWH.Rows
            If String.IsNullOrEmpty(rw.Cells("date").ToString()) Then
                rw.BackColor = Drawing.Color.Green
            Else
                rw.BackColor = Drawing.Color.Red
            End If
        Next



此代码用于asp.net vb代码


this code for asp.net vb code


这篇关于如何用绿色填充datagridview中的选定行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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