当前位置:编程学习 > C#/ASP.NET >>

请教一个关于datagridview控件的问题

当选中datagridview中的任意一个单元格时,其对应的列、行表头同时出现标识箭头(或者列、行表头单元格颜色改变,就像excel一样),这样用户有时就清楚当前点击的时哪一行,哪一列。
--------------------编程问答-------------------- 下面的代码是,光标所在单元格的背景色为红色的例子。
详细说明请参照http://www.bingning.net/source/vb/datagridview/cellcolor.php

'DataGridView1的CellMouseEnter事件处理器
 Private Sub DataGridView1_CellMouseEnter(ByVal sender As Object, _
         ByVal e As DataGridViewCellEventArgs) _
         Handles DataGridView1.CellMouseEnter
     'Header以外的单元格
     If e.ColumnIndex >= 0 And e.RowIndex >= 0 Then
         Dim dgv As DataGridView = CType(sender, DataGridView)
         '变更单元格的Style
         dgv(e.ColumnIndex, e.RowIndex).Style.BackColor = Color.Red
         dgv(e.ColumnIndex, e.RowIndex).Style.SelectionBackColor = Color.Red
     End If
 End Sub

 'DataGridView1的CellMouseLeave事件处理器
 Private Sub DataGridView1_CellMouseLeave(ByVal sender As Object, _
         ByVal e As DataGridViewCellEventArgs) _
         Handles DataGridView1.CellMouseLeave
     'Header以外的单元格
     If e.ColumnIndex >= 0 And e.RowIndex >= 0 Then
         Dim dgv As DataGridView = CType(sender, DataGridView)
         '单元格的Style返回原设定
         '如果单元格的Style删除了,设定为Null
         dgv(e.ColumnIndex, e.RowIndex).Style.BackColor = Color.Empty
         dgv(e.ColumnIndex, e.RowIndex).Style.SelectionBackColor = Color.Empty
     End If
 End Sub


--------------------编程问答-------------------- 用JS写最好
--------------------编程问答-------------------- 用
DevComponents.DotNetBar2.dll
里面的DataGridView就有你说的效果,而且还很漂亮 --------------------编程问答-------------------- DotNetBar --------------------编程问答-------------------- VB 2008默认就有了 你点了就变蓝色了 
补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,