I have an editable WPF DataGrid bound to DataTable, and data loaded from SQL Server page by page using ADO.NET. There are some text fields with type nvarchar(MAX). So the user should be able to edit and save the text inside the DataGrid. All this works well with normal DataGridTextColumns. But it is very inconvenient for the user, therefore I want to show 2 lines visible in the text column and a vertical scroll bar to scroll the remaining.
I tried following both DataGridTextColumn and DataGridTemplateColumn.
Using DataGridTemplateColumn it shows the way we want, but when edit it does not appear in DataSet has changes. (This is required to warn user while navigating through pages) Therefore it doesn’t save the changes.
<DataGridTemplateColumn Header="Full Description" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox x:Name="dgFullDescription"
Text="{Binding FullDescription, Mode=TwoWay}"
TextWrapping="WrapWithOverflow" Height="36"
VerticalScrollBarVisibility="Visible" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
On the otherhand DataGridTextColumn does save changes but couldn’t show scroll bar. If I set the text wrapping then it shows more than 2 lines if it has more characters, and therefore row height are inconsistent.
<DataGridTextColumn Header="ShortDescription" Width="*"
Binding="{Binding ShortDescription, Mode=TwoWay}" >
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
Value="Visible" />
</Style>
</DataGridTextColumn.ElementStyle>
<DataGridTextColumn.EditingElementStyle>
<Style TargetType="TextBox">
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="HorizontalScrollBarVisibility"
Value="Visible" />
</Style>
</DataGridTextColumn.EditingElementStyle>
</DataGridTextColumn>
How can I set the vertical scrollbar inside editable Text Column with fixed row height in WPF DataGrid ?