使用事件更改Datagridview的单元背景色 [英] changing cell backcolor of Datagridview with events

查看:56
本文介绍了使用事件更改Datagridview的单元背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在要向您展示的内容是较大程序的一部分,但是在这一部分中我有问题.我把3种形式的控件组合框,按钮和datagridview

what i gonna show u now is a part from bigger program but in this part i have problem. I put  3 controls in a form  combobox, button and datagridview

当我单击按钮时,组合框中的文本将添加到datagridview表中,并且如果当我单击按钮时组合框为空,则新行中datagridview单元格的背景色保持白色,但是单击按钮时组合框中将包含文本背景色 新行中的datagridview单元的颜色变为红色,我使用rowadded事件对此进行了设置

when i click the button the text in the combobox added to the datagridview table and if combobox was empty when i click the button the backcolor of datagridview cell in the new row stay white but the combobox have text in it when the button clicked the backcolor of datagridview cell in the new row become red i set this up with rowadded event

私有子DataGridView1_Row☎联系人(发件人为对象,e作为DataGridViewRowFyresEventArgs)处理DataGridView1.Row☎联系人
 昏暗的ccc为整数

 对于ccc = 0到DataGridView1.Rows.Count-1
     如果DataGridView1.Rows(ccc).Cells(1).Value.ToString<> "然后
          DataGridView1.Rows(ccc).Cells(1).Style.BackColor = Color.Red
     如果结束
 下一个
结束

Private Sub DataGridView1_RowsAdded(sender As Object, e As DataGridViewRowsAddedEventArgs) Handles DataGridView1.RowsAdded
    Dim ccc As Integer

    For ccc = 0 To DataGridView1.Rows.Count - 1
        If DataGridView1.Rows(ccc).Cells(1).Value.ToString <> "" Then
            DataGridView1.Rows(ccc).Cells(1).Style.BackColor = Color.Red
        End If
    Next
End Sub


比处理的cellMousedoubleclick事件中的事件更多,并使它将当前单元格的背景色更改为绿色

more than that in handeled cellMousedoubleclick event and make it change the current cell backcolor to green


私有子DataGridView1_CellMouseDoubleClick(作为对象发送,作为DataGridViewCellMouseEventArgs发送)处理DataGridView1.CellMouseDoubleClick
  DataGridView1.CurrentCell.Style.BackColor = Color.Green
结束子

Private Sub DataGridView1_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDoubleClick
    DataGridView1.CurrentCell.Style.BackColor = Color.Green
End Sub

现在英特尔一切正常,在此之后添加新行时问题就开始了,此操作使一切恢复到以前的状态

intel now every thing is ok, the problem starts when add new row after that,this action make every thing back like it was before


如您所见,添加333行后,绿色消失了,所以请在添加新行后,任何人都可以帮助我保存更改?

as you can see the green color is disappear after adding the 333 row so please any one can help me to preserve the changings after adding new row ??

推荐答案

代码在哪里?


这篇关于使用事件更改Datagridview的单元背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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