2024年终活动

DevExpress控件使用交流,DevExpress中国社区Dev联系电话 联系电话:023-68661681

如何实现DevExpress XtraGrid网格行的热跟踪(hot-tracking)?

来源:本站原创   发布时间:2012-08-03   浏览:2784次

能否当鼠标悬停在某一个单元格时,鼠标光标显示为手型光标,并且改变网格行的外观?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控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/282.html
扫码咨询
电话咨询
023-68661681
返回
顶部