如何实现DevExpress XtraGrid网格行的热跟踪(hot-tracking)?
作者:zhuhm 来源:本站原创 浏览:Loading...次 发布时间:2012-08-03 评论:0条
能否当鼠标悬停在某一个单元格时,鼠标光标显示为手型光标,并且改变网格行的外观?DevExpress XtraGrid当然可以实现该功能。你需要处理网格视图中的MouseMove和RowCellStyle事件,代码如下:
[C#]
using DevExpress.XtraGrid.Views.Grid;
private int hotTrackRow = DevExpress.XtraGrid.GridControl.InvalidRowHandle;
private int HotTrackRow {
get {
return hotTrackRow;
}
set {
if(hotTrackRow != value) {
int prevHotTrackRow = hotTrackRow;
hotTrackRow = value;
gridView1.RefreshRow(prevHotTrackRow);
gridView1.RefreshRow(hotTrackRow);
if(hotTrackRow >= 0)
gridControl1.Cursor = Cursors.Hand;
else
gridControl1.Cursor = Cursors.Default;
}
}
}
private void gridView1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) {
GridView view = sender as GridView;
GridHitInfo info = view.CalcHitInfo(new Point(e.X, e.Y));
if(info.InRowCell)
HotTrackRow = info.RowHandle;
else
HotTrackRow = DevExpress.XtraGrid.GridControl.InvalidRowHandle;
}
private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e) {
if(e.RowHandle == HotTrackRow)
e.Appearance.BackColor = Color.PaleGoldenrod;
}
[VB.NET]
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Grid
Private HotTrackRowValue As Integer = GridControl.InvalidRowHandle
Private Property HotTrackRow() As Integer
Get
Return HotTrackRowValue
End Get
Set(ByVal Value As Integer)
If HotTrackRowValue <> Value Then
Dim PrevHotTrackRow As Integer
PrevHotTrackRow = HotTrackRowValue
HotTrackRowValue = Value
GridView1.RefreshRow(PrevHotTrackRow)
GridView1.RefreshRow(HotTrackRowValue)
If HotTrackRowValue >= 0 Then
GridControl1.Cursor = Cursors.Hand
Else
GridControl1.Cursor = Cursors.Default
End If
End If
End Set
End Property
Private Sub GridView1_MouseMove(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles GridView1.MouseMove
Dim View As GridView = CType(sender, GridView)
With View.CalcHitInfo(New Point(e.X, e.Y))
If .InRowCell Then
HotTrackRow = .RowHandle
Else
HotTrackRow = GridControl.InvalidRowHandle
End If
End With
End Sub
Private Sub GridView1_RowCellStyle(ByVal sender As Object, ByVal e As RowCellStyleEventArgs) Handles GridView1.RowCellStyle
If e.RowHandle = HotTrackRow Then
e.Appearance.BackColor = Color.PaleGoldenrod
End If
End Sub
技术:.NET
产品:XtraGrid(包含在DevExpress Universal套包中)
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [http://www.devexpresscn.com/]
本文地址:http://www.devexpresscn.com/DevExpress-Resources/Documentation-182.html
关键字: DevExpress XtraGrid
评论列表
暂无评论
请谈谈你的看法 请使用IE或者Firefox浏览器,暂不支持Chrome!
慧都控件网为DevExpress界面控件的中国地区唯一正式授权经销商,正版控件销售公司,授权代理商,经销商及合作伙伴。
电话:400-700-1020
023-66090381
邮箱:sales@evget.com
相关资源
- 如何删除ASPxGridView选定的行
- 如何移动ASPxGridView选定行到另一个ASPxGridView
- 如何删除ASPxGridView的选定行(绑定到数据库)
- XtraGrid如何清除网格
- XtraGrid可以导出到一个PDF文件吗?
- XtraGrid是线程安全的吗?
- 如何强制Grid单元格显示提示 即使单元格内容可见
- ASPxGridView能否实现多表头显示和统计
- GridView导出到Excel中不能导出自定义日期
- XtraGrid能否只计算可见数据行的数目
- XtraGrid 中文字符导出到Excel时不能显示
- 创建自定义XtraVerticalGrid控件子节点来实现自定义行缩进
- GridView 快速遍历
- 在GridControl中如何打开Excel文件
- GridView详细视图的服务器模式功能使用方法
- 如何绑定实体框架对象到XtraGrid
- 使用CreatePrintInfoInstance导出自定义文本和Gridbands
- GridView中格式化数据显示的问题
- 显示AgDataGrid主从数据
- GridControl运行时是否可以不选中任何行