| |
 |
Scrollbar Annotations
When grids contain many rows, locating those with validation errors, and those that are focused or selected, can be difficult. To help locate these rows expeditiously, display scrollbar annotations. The latter are colored marks on the vertical scrollbar that reflect the location of corresponding rows in the grid.


How to Enable
The GridView.OptionsScrollAnnotations property provides access to options that allow you to enable/disable specific annotations.
- ShowErrors — specifies whether to mark rows with validation errors
- ShowFocusedRow — specifies whether to mark the focused row
- ShowSelectedRows — specifies whether to mark selected rows
- ShowCustomAnnotations — specifies whether to mark rows with custom annotations provided using a dedicated event (see below)
Scrollbar annotations are disabled if a property equals to Default. Set the property to True to enable them.
C# |
gridView.OptionsScrollAnnotations.ShowFocusedRow = DefaultBoolean.True;
|
VB |
gridView.OptionsScrollAnnotations.ShowFocusedRow = DefaultBoolean.True
|
The grid control also displays scrollbar annotations for search requests if the Find Panel is in search mode.
Limitations
Scrollbar annotations have the following limitations.

Custom Annotations
The GridView.CustomScrollAnnotation event allows you to provide data about the required custom annotations. Data is represented by the GridScrollAnnotationInfo type, which exposes the following properties.
- RowHandle — handle of the required row (see Row handles in the Rows topic)
- Color — color of the mark on the scrollbar
When handling this event, create data objects and add them to the Annotations collection in the event arguments.
C# |
void OnCustomScrollAnnotation(object sender, GridCustomScrollAnnotationsEventArgs e) {
GridScrollAnnotationInfo info = new GridScrollAnnotationInfo() { RowHandle = 74, Color = Color.Red };
e.Annotations.Add(info);
}
|
VB |
Private Sub OnCustomScrollAnnotation(ByVal sender As Object, ByVal e As GridCustomScrollAnnotationsEventArgs) Handles gridView.CustomScrollAnnotation
Dim info As GridScrollAnnotationInfo = New GridScrollAnnotationInfo()
info.RowHandle = 74
info.Color = Color.Red
e.Annotations.Add(info)
End Sub
|
The SetAnnotations method allows you to set annotations for a row array. Note that this method does not add annotations, but resets them.
C# |
void OnCustomScrollAnnotation(object sender, GridCustomScrollAnnotationsEventArgs e) {
int[] rowHandles = new int[] { 5, 17, 74 };
e.SetAnnotations(Color.Red, rowHandles);
}
|
VB |
Private Sub OnCustomScrollAnnotation(ByVal sender As Object, ByVal e As GridCustomScrollAnnotationsEventArgs) Handles gridView.CustomScrollAnnotation
Dim rowHandles() As Integer = {5, 17, 74}
e.SetAnnotations(Color.Red, rowHandles)
End Sub
|

How to: Create Row Bookmarks Using Scrollbar Annotations and Row Indicators
You can provide users with the ability to bookmark specific rows and navigate between them using the keyboard. To implement this functionality, handle the following events.
C# |
using DevExpress.XtraEditors.Annotations;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.Drawing;
gridView.CustomScrollAnnotation += OnCustomScrollAnnotation;
gridView.CustomDrawRowIndicator += OnCustomDrawRowIndicator;
gridView.ScrollAnnotationsStyle += OnScrollAnnotationsStyle;
gridView.KeyDown += OnKeyDown;
readonly HashSet<int> bookmarks = new HashSet<int>() { 5, 17, 74 };
void OnCustomScrollAnnotation(object sender, GridCustomScrollAnnotationsEventArgs e) {
int[] rowHandles = bookmarks.Select(x => gridView.GetRowHandle(x)).ToArray();
e.SetAnnotations(DevExpress.LookAndFeel.DXSkinColors.IconColors.Blue, rowHandles);
}
readonly AnnotationsStyle style = new AnnotationsStyle();
void OnScrollAnnotationsStyle(object sender, GridScrollAnnotationsStyleEventArgs e) {
var styleColor = style.GetColor(e.Kind);
if(!styleColor.IsEmpty)
e.Color = styleColor;
}
void OnCustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e) {
if(e.RowHandle >= 0) {
if(e.Info.ImageIndex == GridPainter.IndicatorError ||
e.Info.ImageIndex == GridPainter.IndicatorFocusedError) {
e.Info.ImageIndex = (e.RowHandle == gridView.FocusedRowHandle) ? GridPainter.IndicatorFocused : -1;
}
if(!bookmarks.Contains(gridView.GetDataSourceRowIndex(e.RowHandle)))
return;
e.DefaultDraw();
var bookmarkImage = svgImageCollection.GetImage("bookmark", GetPalette(), ScaleDPI.ScaleSize(new Size(8, 8)));
var imageBounds = PlacementHelper.Arrange(bookmarkImage.Size, e.Bounds, ContentAlignment.MiddleLeft);
e.Cache.DrawImageUnscaled(bookmarkImage, imageBounds);
e.Handled = true;
}
}
Utils.Design.ISvgPaletteProvider GetPalette() {
return Utils.Svg.SvgPaletteHelper.GetSvgPalette(gridControl.LookAndFeel, Utils.Drawing.ObjectState.Normal);
}
void OnKeyDown(object sender, KeyEventArgs e) {
if(e.KeyData == (Keys.F2 | Keys.Control) || e.KeyData == (Keys.B | Keys.Control))
e.Handled = ToggleBookmark(gridView.FocusedRowHandle);
if(e.KeyData == Keys.F2)
e.Handled = gridView.MoveToNextScrollAnnotation(ScrollAnnotationKind.Custom);
if(e.KeyData == (Keys.F2 | Keys.Shift))
e.Handled = gridView.MoveToPrevScrollAnnotation(ScrollAnnotationKind.Custom);
}
bool ToggleBookmark(int handle) {
int dataIndex = gridView.GetDataSourceRowIndex(handle);
if(dataIndex < 0)
return false;
if(bookmarks.Contains(dataIndex))
bookmarks.Remove(dataIndex);
else
bookmarks.Add(dataIndex);
gridView.RefreshScrollAnnotations(ScrollAnnotationKind.Custom);
gridView.InvalidateRow(handle);
return true;
}
|
VB |
Imports DevExpress.XtraEditors.Annotations
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Views.Grid.Drawing
Private ReadOnly bookmarks As New HashSet(Of Integer)() From {5, 17, 74}
Private Sub OnCustomScrollAnnotation(ByVal sender As Object, ByVal e As GridCustomScrollAnnotationsEventArgs) Handles gridView.CustomScrollAnnotation
Dim rowHandles() As Integer = bookmarks.Select(Function(x) gridView.GetRowHandle(x)).ToArray()
e.SetAnnotations(DevExpress.LookAndFeel.DXSkinColors.IconColors.Blue, rowHandles)
End Sub
Private ReadOnly style As New AnnotationsStyle()
Private Sub OnScrollAnnotationsStyle(ByVal sender As Object, ByVal e As GridScrollAnnotationsStyleEventArgs) Handles gridView.ScrollAnnotationsStyle
Dim styleColor = style.GetColor(e.Kind)
If Not styleColor.IsEmpty Then
e.Color = styleColor
End If
End Sub
Private Sub OnCustomDrawRowIndicator(ByVal sender As Object, ByVal e As RowIndicatorCustomDrawEventArgs) Handles gridView.CustomDrawRowIndicator
If e.RowHandle >= 0 Then
If e.Info.ImageIndex = GridPainter.IndicatorError OrElse e.Info.ImageIndex = GridPainter.IndicatorFocusedError Then
e.Info.ImageIndex = If((e.RowHandle = gridView.FocusedRowHandle), GridPainter.IndicatorFocused, -1)
End If
If (Not bookmarks.Contains(gridView.GetDataSourceRowIndex(e.RowHandle))) Then
Return
End If
e.DefaultDraw()
Dim bookmarkImage = svgImageCollection.GetImage("bookmark", GetPalette(), ScaleDPI.ScaleSize(New Size(8, 8)))
Dim imageBounds = PlacementHelper.Arrange(bookmarkImage.Size, e.Bounds, ContentAlignment.MiddleLeft)
e.Cache.DrawImageUnscaled(bookmarkImage, imageBounds)
e.Handled = True
End If
End Sub
Private Function GetPalette() As Utils.Design.ISvgPaletteProvider
Return Utils.Svg.SvgPaletteHelper.GetSvgPalette(gridControl.LookAndFeel, Utils.Drawing.ObjectState.Normal)
End Function
Private Sub OnGridKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles gridView.KeyDown
If e.KeyData = Keys.F2 Then
e.Handled = gridView.MoveToNextScrollAnnotation(ScrollAnnotationKind.Custom)
End If
If e.KeyData = (Keys.F2 Or Keys.Shift) Then
e.Handled = gridView.MoveToPrevScrollAnnotation(ScrollAnnotationKind.Custom)
End If
If e.KeyData = (Keys.F2 Or Keys.Control) OrElse e.KeyData = (Keys.B Or Keys.Control) Then
e.Handled = ToggleBookmark(gridView.FocusedRowHandle)
End If
End Sub
Private Function ToggleBookmark(ByVal handle As Integer) As Boolean
Dim dataIndex As Integer = gridView.GetDataSourceRowIndex(handle)
If dataIndex < 0 Then
Return False
End If
If bookmarks.Contains(dataIndex) Then
bookmarks.Remove(dataIndex)
Else
bookmarks.Add(dataIndex)
End If
gridView.RefreshScrollAnnotations(ScrollAnnotationKind.Custom)
gridView.InvalidateRow(handle)
Return True
End Function
|

See Also
Is this topic helpful?
Additional Feedback
Close
|