DevExpress控件使用交流,DevExpress中国社区 售前咨询
当前位置: 首页 > 开发资源 » 使用教程 » 如何实现DevExpress XtraGrid网格行的热跟踪(hot-tracking)?

如何实现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

评论列表

暂无评论

请谈谈你的看法 请使用IE或者Firefox浏览器,暂不支持Chrome!

昵称 不填则默认为游客评论

DevExpress DXperience DXv2 v12

DevExpress DXperience 下载 download

DevExpress购买、价格、授权

慧都控件网为DevExpress界面控件的中国地区唯一正式授权经销商,正版控件销售公司,授权代理商,经销商及合作伙伴。

电话:400-700-1020
        023-66090381

邮箱:sales@evget.com

>>如何选择正规控件购买渠道