wpf-18068-controls-and-libraries-data-grid-paging-and-scrolling-scrollbar-annotations.md
The GridControl‘s TableView and TreeListView can display specific colored marks within the vertical scrollbar: scrollbar annotations. These marks correspond to specific grid rows (or treelist nodes).
View Example: Scrollbar Annotations
The GridControl views can display the scrollbar annotations marks for the following items.
Tip
The GridControl supports the display of annotation marks for rows that meet custom criteria. See the Adding custom annotations section.
Note
Limitations When the GridControl is bound to data in the Server Mode, the control supports scrollbar annotations for the focused and selected rows only.
To enable scrollbar annotations, use the TableView.ScrollBarAnnotationMode (or TreeListView.ScrollBarAnnotationMode) property. You can set this property to the following flags.
The code sample below demonstrates how to enable scrollbar annotations for selected and focused rows.
<dxg:GridControl ItemSource="{Binding Customers}">
<dxg:GridControl.View>
<dxg:TableView ScrollBarAnnotationMode="Selected, Focused" />
</dxg:GridControl.View>
</dxg:GridControl>
In addition to built-in annotations, you can enable custom scrollbar annotations for:
Displaying annotations for a predefined set of rows.
You can define a set of rows and their annotations in the following way.
Create a collection of ScrollBarAnnotationRowInfo objects, each of these objects should store the following information:
Handle the view’s TableView.ScrollBarAnnotationsCreating (or TreeListView.ScrollBarAnnotationsCreating event).
Pass a collection of rows with corresponding annotations to the event argument’s ScrollBarAnnotationsCreatingEventArgs.CustomScrollBarAnnotations property.
Displaying annotations for rows that fit custom criteria.
To display annotation marks dynamically based on row values follow the steps below.
The code sample below demonstrates how to display marks for rows, whose Visits field value is 0.
<dxg:GridControl Name="grid" ItemsSource="{Binding Customers}" AllowLiveDataShaping="True">
<dxg:GridControl.View>
<dxg:TableView x:Name="tableView" AllowPerPixelScrolling="True"
ScrollBarAnnotationMode="Custom"
ScrollBarCustomRowAnnotation="tableView_ScrollBarCustomRowAnnotation">
</dxg:TableView>
</dxg:GridControl.View>
</dxg:GridControl>
using System.Windows;
using System.Windows.Media;
namespace WpfApplication1 {
public partial class Window1 : Window {
public Window1() {
InitializeComponent();
}
private void tableView_ScrollBarCustomRowAnnotation(object sender, DevExpress.Xpf.Grid.ScrollBarCustomRowAnnotationEventArgs e) {
Model.Customer row = (Model.Customer)e.Row;
// Display marks for customers with zero visits
if(row.Visits == 0) {
e.ScrollBarAnnotationInfo = new DevExpress.Xpf.Grid.ScrollBarAnnotationInfo() {
Alignment = DevExpress.Xpf.Grid.ScrollBarAnnotationAlignment.Right,
Brush = Brushes.Red,
MinHeight = 3,
Width = 10
};
}
}
}
}
The image below illustrates the result.
Note
To automatically update custom scrollbar annotations, it is required to set the DevExpress.Xpf.Grid.GridControl.AllowLiveDataShaping property to true.
To customize the appearance of built-in scrollbar annotations, use the TableView.ScrollBarAnnotationsAppearance (or the TreeListView.ScrollBarAnnotationsAppearance) property. This property provides access to the ScrollBarAnnotationsAppearance object that stores appearance settings of all the built-in annotations.
The ScrollBarAnnotationsAppearance object properties correspond to built-in annotation marks. The following appearance settings are available.
| Property | Description |
|---|---|
| ScrollBarAnnotationsAppearance.FocusedRow | Gets or sets appearance settings for scrollbar annotation marks that correspond to focused row. This is a dependency property. |
| ScrollBarAnnotationsAppearance.InvalidCells | Gets or sets appearance settings for scrollbar annotation marks that correspond to invalid cells. This is a dependency property. |
| ScrollBarAnnotationsAppearance.InvalidRows | Gets or sets appearance settings for scrollbar annotation marks that correspond to invalid rows. This is a dependency property. |
| ScrollBarAnnotationsAppearance.SearchResult | Gets or sets appearance settings for scrollbar annotation marks that correspond to search results. This is a dependency property. |
| ScrollBarAnnotationsAppearance.Selected | Gets or sets the appearance settings for scrollbar annotation marks that correspond to selected rows. This is a dependency property. |
The code sample below demonstrates how to customize a scrollbar annotation mark that corresponds to a focused row.
<dxg:GridControl ...>
<dxg:GridControl.View>
<dxg:TableView ScrollBarAnnotationMode="All">
<dxg:TableView.ScrollBarAnnotationsAppearance>
<dxg:ScrollBarAnnotationsAppearance>
<dxg:ScrollBarAnnotationsAppearance.FocusedRow>
<dxg:ScrollBarAnnotationInfo Alignment="Full" Brush="Blue"/>
</dxg:ScrollBarAnnotationsAppearance.FocusedRow>
</dxg:ScrollBarAnnotationsAppearance>
</dxg:TableView.ScrollBarAnnotationsAppearance>
</dxg:TableView>
</dxg:GridControl.View>
</dxg:GridControl>