如何根据另一个列值更改datagridview列backcolor [英] how to change datagridview column backcolor based on another column value

查看:94
本文介绍了如何根据另一个列值更改datagridview列backcolor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨......我是使用vb的新手,非常感谢你的帮助..我想根据同一datagridview中的rating列更改datagridview中的状态列backcolor。例如,如果rating列=good则状态列backcolor应该是绿色,如果rating = satisf,那么状态backcolor应该是黄色等我怎么能在vb 2012中做到这一点?非常感谢。

Hi...am new in using vb and really appreciate your help..i wanted to change a status column backcolor in datagridview based on the rating column in the same datagridview.For example if the rating column="good" then status column backcolor should be green,if rating=satisfactory then status backcolor should be yellow etc. how can i do that in vb 2012?thanks a lot.

推荐答案

你好,

您可以使用 CellEndEdit 事件来满足您的要求。有关 CellEndEdit 的详细信息,请点击此链接

Hello ,
You can use CellEndEdit event to fulfill your requirement . for more details on CellEndEdit follow this Link
private void dgv_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {
     //now if rating column in 2nd position of datagridview
     if(e.ColumnIndex==1)
       {
          if(dgv.Rows[e.RowIndex].Cells[1].Value=="good") //compare the value
             dgv.Rows[e.RowIndex].Cells[2].BackColor = Color.Green;
          else
             dgv.Rows[e.RowIndex].Cells[2].BackColor = Color.Yellow;

       }
    }



谢谢


thanks


这篇关于如何根据另一个列值更改datagridview列backcolor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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