Back to Devexpress

GridOptionsBehavior.AllowPixelScrolling Property

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridoptionsbehavior-8ec80679.md

latest6.4 KB
Original Source

GridOptionsBehavior.AllowPixelScrolling Property

Gets or sets whether smooth pixel-based vertical scrolling is enabled for rows.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
[DefaultValue(DefaultBoolean.Default)]
[XtraSerializableProperty]
public virtual DefaultBoolean AllowPixelScrolling { get; set; }
vb
<DefaultValue(DefaultBoolean.Default)>
<XtraSerializableProperty>
Public Overridable Property AllowPixelScrolling As DefaultBoolean

Property Value

TypeDefaultDescription
DefaultBooleanDefault

A DefaultBoolean value that specifies whether smooth pixel-based vertical scrolling is enabled for rows.

|

Available values:

NameDescriptionReturn Value
True

The value is true.

|

0

| | False |

The value is false.

|

1

| | Default |

The value is specified by a global option or a higher-level object.

|

2

|

Property Paths

You can access this nested property as listed below:

Object TypePath to AllowPixelScrolling
GridView

.OptionsBehavior .AllowPixelScrolling

|

Remarks

If the AllowPixelScrolling property is set to Default or False , pixel scrolling is disabled. If this property is set to True , smooth pixel-based vertical scrolling is enabled for rows.

Note

When pixel scrolling is active:

Note

Pixel-based scrolling is not in effect if any of the following features are enabled:

When pixel scrolling is enabled, change the GridView.TopRowPixel property and/or call the GridView.SmoothScroll method to scroll through rows in code.

Pixel Scrolling and Custom Row Heights

Pixel scrolling is affected by the GridView.CalcRowHeight event handler. In the code below, row heights are calculated dynamically. Because of that, pixel scrolling is disabled even though the AllowPixelScrolling is set to True.

csharp
public Form1()
{
    InitializeComponent();
    //. . .
    gridView1.OptionsBehavior.AllowPixelScrolling = DevExpress.Utils.DefaultBoolean.True;
}

private void gridView1_CalcRowHeight(object sender, DevExpress.XtraGrid.Views.Grid.RowHeightEventArgs e)
{
    e.RowHeight = MethodThatCalculatesRowHeights();
}
vb
Public Sub New()
    InitializeComponent()
    '. . .
    gridView1.OptionsBehavior.AllowPixelScrolling = DevExpress.Utils.DefaultBoolean.True
End Sub

Private Sub gridView1_CalcRowHeight(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.RowHeightEventArgs)
    e.RowHeight = MethodThatCalculatesRowHeights()
End Sub

In order to re-enable pixel scrolling, you have to create a GridView descendant that overrides the boolean IsAllowPixelScrollingAutoRowHeight property. Then replace parts of the code that initialize your Views so that these View are instances of this custom class.

csharp
public class MyGridView: GridView {
    protected override bool IsAllowPixelScrollingAutoRowHeight {
        get { return true; }
    }
}

//Form1.designer.cs
private void InitializeComponent()
{
    //. . .
    this.gridView1 = new MyGridView();
    //. . .
}
private MyGridView gridView1;
vb
Public Class MyGridView
    Inherits GridView

    Protected Overrides ReadOnly Property IsAllowPixelScrollingAutoRowHeight() As Boolean
        Get
            Return True
        End Get
    End Property
End Class

'Form1.designer.vb
Private Sub InitializeComponent()
    '. . .
    Me.gridView1 = New MyGridView()
    '. . .
End Sub
Private gridView1 As MyGridView

Important

Use pixel scrolling with caution when you calculate row heights dynamically. If you change heights of the same rows throughout the form display, the total client region height changes, and users may be unable to scroll the View up or down to the first (last) record.

To make sure this never happens, use the GridView.CalcRowHeight event to provide custom row height values once, and never change these heights again while the same Form instance exists.

Online Video

DevExpress WinForms: Grid Pixel Scrolling.

See Also

TopRowPixel

SmoothScroll(Int32)

AllowPixelScrolling

GridOptionsBehavior Class

GridOptionsBehavior Members

DevExpress.XtraGrid.Views.Grid Namespace