【问题标题】:Visual Basic DataRow/DataSet/DataGrid change specific cell text colorVisual Basic DataRow/DataSet/DataGrid 更改特定单元格文本颜色
【发布时间】:2018-01-17 17:50:49
【问题描述】:
For Each row As DataRow In ds.Tables(0).Rows
                    If (row("Flag") And 1 = 1) Then
                        row("Col_1") = Color.Red
                    End If
                    If (row("Flag") And 2 = 2) Then
                        row("Col_2") = Color.Red
                    End If
                    If (row("Flag") And 4 = 4) Then
                        row("Col_3") = Color.Red
                    End If
                    If (row("Flag") And 8 = 8) Then
                        row("Col_4") = Color.Red
                    End If
                Next

我想根据标志将特定单元格设置为红色。我可以访问 DataSet 和 DataGrid,但不能访问 DataGridView。有没有一种简单的方法可以用 DataGrid 完成这个?我相信我现在拥有的东西不起作用,因为 DataRow 只是内存数据。

【问题讨论】:

  • 是的,这是 vb.net,我的错
  • row("Col_1") = Color.Red 放在任何If 语句之前只是为了查看单元格是否会被着色。

标签: vb.net datagrid


【解决方案1】:

你为什么用1=1,就用True...等一下

再次查看您的代码...您正在进行位操作...我认为您的 if 语句中缺少一些括号

应该是If ((row("Flag") And 1) = 1) Then .... 其余部分相同

【讨论】:

  • 我改为在 ForEach 中使用 DataGridItem,因为 DataGrid.Item 是一个 DataGridItem。 Cells 对象有一个 ForeColor,我将使用它来将颜色设置为红色,并且我正在使用 CInt 来投射 Cells 的 Text 对象
猜你喜欢
  • 1970-01-01
  • 2021-04-06
  • 1970-01-01
  • 2017-08-07
  • 2011-07-29
  • 2012-08-02
  • 2023-03-28
相关资源
最近更新 更多