C# DataGridView是否将线条颜色选择为“无”?

C# DataGridView是否将线条颜色选择为“无”?,c#,winforms,datagridview,C#,Winforms,Datagridview,如果dataGridView1cellFormatting I根据线值下的对象更改背景色,网格将正确显示所有信息。这也行得通。我的网格上的最后一个事件是dataGridView1\u CellPaint,它检查是否是添加图标的标题 在我尝试去掉所选行(或单元格)的颜色之前,一切都很好。我想要的是去掉所选线条的颜色。我尝试将其设置为“透明”,但当控件绑定数据时,线条为灰色,当我们调整列大小时,文本不可读 如何在不突出显示所选行的情况下显示DataGridView中的数据?您可以将Selection

如果dataGridView1cellFormatting I根据线值下的对象更改背景色,网格将正确显示所有信息。这也行得通。我的网格上的最后一个事件是dataGridView1\u CellPaint,它检查是否是添加图标的标题

在我尝试去掉所选行(或单元格)的颜色之前,一切都很好。我想要的是去掉所选线条的颜色。我尝试将其设置为“透明”,但当控件绑定数据时,线条为灰色,当我们调整列大小时,文本不可读


如何在不突出显示所选行的情况下显示DataGridView中的数据?

您可以将
SelectionForeColor
SelectionBackColor
属性设置为要更改突出显示颜色的颜色。这可以在DataGridView的
DefaultCellStyle
属性上设置,也可以在单个单元格本身上设置。这样,选定行时颜色不会改变

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
Private子dgv_CellFormatting(ByVal发送方作为System.Object,ByVal e作为System.Windows.Forms.DataGridViewCellFormattingEventArgs)处理dgv.CellFormatting
如果e.RowIndex<0,则退出Sub
如果e.RowIndex Mod 2=0,则
e、 CellStyle.BackColor=颜色.橙色
其他的
e、 CellStyle.BackColor=颜色.红色
如果结束
'使所选单元格具有相同的颜色
e、 CellStyle.SelectionBackColor=e.CellStyle.BackColor
e、 CellStyle.SelectionForeColor=e.CellStyle.ForeColor
端接头