I would like to know if it's posible to have the horizontal scrollbar that does like in excel, scroll to the right and will show blank columns? The datagrid scrollbar only scrolls from the first column on the left to the last column on the right and vice versa.
1 Answers
0
votes
If you have a
<DataGrid Name="grid"
ScrollViewer.ScrollChanged="DataGrid_ScrollChanged" />
you can add further columns on demand like this
private void DataGrid_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
if (e.HorizontalOffset >= e.ExtentWidth - e.ViewportWidth)
{
grid.Columns.Add(new DataGridTextColumn() { Header = grid.Columns.Count + 1 });
}
}
Of course you have to add a row to see the effect.
grid.Items.Add("Test Row");