彩票走势图

如何实现DevExpress XtraGrid网格行的热跟踪

原创|其它|编辑:郝浩|2012-09-25 11:04:11.000|阅读 420 次

概述:能否当鼠标悬停在某一个单元格时,鼠标光标显示为手型光标,并且改变网格行的外观?DevExpress XtraGrid当然可以实现该功能。你需要处理网格视图中的MouseMove和RowCellStyle事件,代码如下:

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

能否当鼠标悬停在某一个单元格时,鼠标光标显示为手型光标,并且改变网格行的外观?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



标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@cahobeh.cn

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
相关产品
DevExpress Universal Subscription

行业领先的界面控件开发包,帮助企业构建卓越应用!

DevExpress WPF Subscription

高效MVVM开发模式,WPF界面解决方案首选工具,帮助企业实现酷炫动效界面。

DevExpress Silverlight Controls

高性价比高实用性的Silverlight用户界面控件套包,拥有大量的示例和帮助文档,开发者能够快速上手!

DevExpress WinForms Subscription

为Windows Forms平台创建具有影响力的业务解决方案,高性价比WinForms界面控件套包。

DevExpress DXperience Subscription

高性价比的企业级.NET用户界面套包,助力企业创建卓越应用!

title
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP