I have created simple DataGrid with 4 columns, which go outside the bounds of DataGrid, and horizontal scrollbar is not showing. I tried setting width to each column but nothing
this was actually a major issue to me since I am creating many columns and allow the user to filter by having filter controls in the header.
When the user scrolls to the right and places a filter in a column and NO rows are returned because of these criteria then the entire grid would move to the left (all columns to the default left position) and the horizontal scrollbar would disappear so the user can't scroll to the filter column to undo his/her action!!
Major pain!
The 'hack' I have just placed in the code is a way around it: (the _dv pointing at a DataView from a DataTable)
// construct an overall sql filter statement
string sqlFilter = _setttings.SGColumns.GetFilterSQL();
BindingListCollectionView view = CollectionViewSource.GetDefaultView(gridMain.ItemsSource) as BindingListCollectionView;
if (view != null)
view.CustomFilter = sqlFilter; // "XGROUP = 'E' AND GEOG = 'U'";
if (view != null && _dv.Count == 0)
{
gridMain.ItemsSource = null;
gridMain.Items.Add("hello");
_RowHeightTemp = gridMain.RowHeight;
gridMain.RowHeight = 0;
}
else
{
if (gridMain.Items.Count == 1 && gridMain.Items[0].ToString() == "hello")
{
gridMain.Items.Clear();
gridMain.ItemsSource = _dv;
view = CollectionViewSource.GetDefaultView(gridMain.ItemsSource) as BindingListCollectionView;
view.CustomFilter = sqlFilter;
gridMain.RowHeight = _RowHeightTemp;
}
}
This now ensures that the grid stays in its exact position when the no rows are displayed!