读书人

DataGridView选中行的背景色怎么去掉

发布时间: 2013-06-25 23:45:42 作者: rapoo

DataGridView选中行的背景色如何去掉
DataGridView选中的行总有背景色,也就是DefaultCellStyle.SelectionBackColor这个属性。
这个属性不能设置成空,设成空则为默认蓝色。

还有DataGridView默认选中第一行或第一个单元格。如何设置不选中任何一行?
[解决办法]
private void dgv_SelectionChanged(object sender, EventArgs e)
{
DataGridView dgv = sender as DataGridView;
dgv.ClearSelection();
}
[解决办法]

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With DataGridView1
.ColumnCount = 6
.Rows.Add(10)
.DefaultCellStyle.SelectionBackColor = .DefaultCellStyle.SelectionForeColor
End With
End Sub

Private Sub DataGridView1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.GotFocus
DataGridView1.CurrentCell = Nothing
End Sub
End Class


[解决办法]
dataGridView1.ClearSelection();
或者
dataGridView1.CurrentCell=null;


if (ds.Tables[0].Rows.Count > 0)
{
dataGridView1.Rows[0].Selected = false
}

读书人网 >VB Dotnet

热点推荐