datagridview 数据绑定 实现单元格颜色

yjl1393422 2009-10-19 04:33:28
数据绑定到datagridview控件 ,根据绑定数据的不同,使datagrieview单元格设置不同的颜色。
不用数据绑定的方式,从数据库中一个个检索,我会,但是由于数据量比较大,刷新比较慢
请哪位高手指点
...全文
178 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
想飞的狼 2009-10-20
  • 打赏
  • 举报
回复
datagridview在调用大量数据时就是慢
dw.ColumnHeadersDefaultCellStyle.BackColor = Color.SlateGray
zhu314746943 2009-10-19
  • 打赏
  • 举报
回复
DataGridView1.AlternatingRowsDefaultCellStyle.ForeColor = _
Color.Red
DataGridView1.GridColor = Color.RoyalBlue
wuyq11 2009-10-19
  • 打赏
  • 举报
回复
Private Sub customerDataGridView_CellFormatting(ByVal sender As Object, ByVal e AsDataGridViewCellFormattingEventArgs) Handles customerDataGridView.CellFormatting
If Me.customerDataGridView.Columns(e.ColumnIndex).Name = "" Then
If e.Value IsNot Nothing Then
If e.Value.ToString = "" e.CellStyle.BackColor = Color.Yellow
End If
End If
End If
End Sub

或DataGridView1.Columns(0).DefaultCellStyle.BackColor = Color.Aqua
DataGridView1.RowsDefaultCellStyle.BackColor = Color.Yellow
DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.GreenYellow
DataGridView1.Rows(2).DefaultCellStyle.BackColor = Color.Pink

Private Sub dataGridView1_CellPainting(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEventArgs)
Using brush As New SolidBrush(Color.Red)
e.Graphics.FillRectangle(brush, e.CellBounds)
e.Handled = True
End Using
End Sub
jane_zhao 2009-10-19
  • 打赏
  • 举报
回复
Private Sub datagidview1_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles datagidview1.CellFormatting
If Not IsDBNull(e.Value) Then
Select Case datagidview1.Rows(e.RowIndex).Cells("TX_FLAG").Value.ToString.Trim
Case "0", "2"
e.CellStyle.ForeColor = Color.Blue
Case "3"
e.CellStyle.ForeColor = Color.Red
End Select
.....
Else
e.Value = ""
End If
End Sub
试试看,数据多的时候慢不。

16,718

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧