本示例展示了如何通过 GridView.CustomDrawRowIndicator 事件定制 行指示器面板 中的单元格。
我们更改了在单元格中显示的文本并且保持 CustomDrawEventArgs.Handled 参数被设置为 false,而没有在此事件中绘制单元格。 在这种情况下,在事件处理程序执行完毕之后,单元格被根据 RowIndicatorCustomDrawEventArgs.Info 对象的设置进行绘制 (绘制新的显示文本)。 indicatorIcon 变量用于控制是否绘制标准的图标。 如果此属性的值为 false,则为了防止显示图像,而把 ImageIndex 属性值设置为 -1。
C# | 复制代码 |
---|---|
using DevExpress.XtraGrid.Views.Grid; //A flag specifying whether to draw default indicator glyphs bool indicatorIcon = true; private void gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e) { GridView view = (GridView)sender; //Check whether the indicator cell belongs to a data row if(e.Info.IsRowIndicator && e.RowHandle > 0) { e.Info.DisplayText = "Row " + e.RowHandle.ToString(); if(!indicatorIcon) e.Info.ImageIndex = -1; } } |
Visual Basic | 复制代码 |
---|---|
Imports DevExpress.XtraGrid.Views.Grid 'A flag specifying whether to draw default indicator glyphs Dim indicatorIcon As Boolean = True Private Sub gridView1_CustomDrawRowIndicator(ByVal sender As Object, _ ByVal e As RowIndicatorCustomDrawEventArgs) Handles gridView1.CustomDrawRowIndicator Dim view As GridView = CType(sender, GridView) 'Check whether the indicator cell belongs to a data row If e.Info.IsRowIndicator And e.RowHandle > 0) Then e.Info.DisplayText = "Row " + e.RowHandle.ToString() If Not indicatorIcon Then e.Info.ImageIndex = -1 End If End Sub |