【问题标题】:DataGridView SelectLine color to none?DataGridView SelectLine 颜色为无?
【发布时间】:2008-12-02 15:24:42
【问题描述】:
网格正确显示所有信息,在事件 dataGridView1cellFormatting 中,我根据行值下的对象更改背景色。这也有效。我在网格上的最后一个事件是 dataGridView1_CellPainting 检查它是否是添加图标的标题。
一切都很好,直到我尝试取出所选行的颜色(或它做同样事情的单元格)。我想要的是取出所选线条的颜色。我尝试将其设置为“透明”,但是当控件绑定数据时,该行是灰色的,当我们调整列大小时,文本不可读。
如何在 DataGridView 中显示数据而不突出显示选定的行?
【问题讨论】:
标签:
c#
winforms
datagridview
【解决方案1】:
您可以将SelectionForeColor 和SelectionBackColor 属性设置为您想要更改突出显示颜色的任何颜色。这可以在 DataGridView 上的 DefaultCellStyle 属性上设置,也可以在单个单元格本身上设置。 This way the colors will not change when the row is selected.
Private Sub dgv_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgv.CellFormatting
If e.RowIndex < 0 Then Exit Sub
If e.RowIndex Mod 2 = 0 Then
e.CellStyle.BackColor = Color.Orange
Else
e.CellStyle.BackColor = Color.Red
End If
'Make the selected cell the same color
e.CellStyle.SelectionBackColor = e.CellStyle.BackColor
e.CellStyle.SelectionForeColor = e.CellStyle.ForeColor
End Sub