George
George

Reputation: 211

C# WPF DataGrid vertical scroll

I see the following behavior with a WPF Datagrid. When there are more items then the height of the view area, the vertical scroll is available. When I click on the last row in the view, an automatic scroll occurs where the row that was just below the last comes into view.

The first column of the datagrid is a checkbox. When the user clicks on this last row, I'm not getting the event for checkbox clicks. The checkboxes in all other rows work OK.

I'd like to disable the automatic scroll, but can't figure how to do it.

<Style x:Key="SingleClickEditing"  TargetType="{x:Type toolkit:DataGridCell}">
     <EventSetter Event="CheckBox.Checked" Handler="OnChecked"/>
     <EventSetter Event="CheckBox.Unchecked" Handler="OnChecked"/>
</Style>

Upvotes: 4

Views: 3053

Answers (2)

George
George

Reputation: 211

I found the solution here: WPF DataGrid: how do I stop auto scrolling when a cell is clicked?

I changed the style of the DataGrid

 <Style x:Key="SingleClickEditing"  TargetType="{x:Type toolkit:DataGridCell}">
       <EventSetter Event="CheckBox.Checked" Handler="OnChecked"/>
       <EventSetter Event="CheckBox.Unchecked" Handler="OnChecked"/>
       <EventSetter Event="Control.RequestBringIntoView" Handler="DataGrid_Documents_RequestBringIntoView"  />
 </Style>


private void DataGrid_Documents_RequestBringIntoView(object sender,    RequestBringIntoViewEventArgs e)
{
    e.Handled = true;
}

Upvotes: 3

Mark
Mark

Reputation: 3123

There is a property on the Datagrid that you should be able to set that would determine if Vertical, Horizontal, Both, or None (in regards to scroll bars) are visible.

Upvotes: 0

Related Questions