简体   繁体   English

根据单元格值对datagridview中的单元格进行颜色编码

[英]Color coding cells in datagridview based on cell value

I'm creating a daily planner, in which tasks are entered into a datagridview as follows: 我正在创建一个每日计划程序,在其中将任务输入到datagridview ,如下所示:

图片

Tasks also have a priority set by the user, as seen above. 如上所示,任务还具有由用户设置的优先级。

I'm trying to achieve the following, however, I'm not sure how to code this: 我正在尝试实现以下目标,但是,我不确定如何编写此代码:

If the priority is set to "High" then the cell in which the priority is displayed will change its color to red. 如果将优先级设置为“高”,则显示优先级的单元格的颜色将变为红色。

If the priority is set to "Medium" then the cell in which the priority is displayed will change its color to yellow. 如果将优先级设置为“中”,则显示优先级的单元格的颜色将变为黄色。

If the priority is set to "Low" then the cell in which the priority is displayed will change its color to green. 如果将优先级设置为“低”,则显示优先级的单元格将其颜色变为绿色。

How would I go about achieving such a feature? 我将如何实现这种功能?

Try this: 尝试这个:

For each row As DataGridViewRow In Datagridview1
   If row.Cells(3).Text.Trim  = "High" Then
        row.Cells(3).Style.Backcolor = Color.Red
   Else If row.Cells(3).Text.Trim  = "Low" Then
       ...
   Else If row.Cells(3).Text.Trim = "Medium" Then
      ...
   End If
Next

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM