Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't clear columns every time #145

Merged
merged 1 commit into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions Maui.DataGrid/DataGrid.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,6 @@ private void InitHeaderView()
SetColumnsBindingContext();

_headerView.Children.Clear();
_headerView.ColumnDefinitions.Clear();
ResetSortingOrders();

_headerView.Padding = new(BorderThickness.Left, BorderThickness.Top, BorderThickness.Right, 0);
Expand All @@ -1274,7 +1273,14 @@ private void InitHeaderView()

col.ColumnDefinition ??= new(col.Width);

_headerView.ColumnDefinitions.Add(col.ColumnDefinition);
if (i > _headerView.ColumnDefinitions.Count - 1)
{
_headerView.ColumnDefinitions.Add(col.ColumnDefinition);
}
else if (_headerView.ColumnDefinitions[i] != col.ColumnDefinition)
{
_headerView.ColumnDefinitions[i] = col.ColumnDefinition;
}

if (!col.IsVisible)
{
Expand All @@ -1288,6 +1294,14 @@ private void InitHeaderView()
Grid.SetColumn(col.HeaderView, i);
_headerView.Children.Add(col.HeaderView);
}

if (_headerView.ColumnDefinitions.Count > Columns.Count)
{
for (var i = _headerView.ColumnDefinitions.Count - 1; i > Columns.Count - 1; i--)
{
_headerView.ColumnDefinitions.RemoveAt(i);
}
}
}

private void ResetSortingOrders()
Expand Down
15 changes: 13 additions & 2 deletions Maui.DataGrid/DataGridRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public object RowToEdit

private void CreateView()
{
ColumnDefinitions.Clear();
Children.Clear();

SetStyling();
Expand All @@ -80,7 +79,14 @@ private void CreateView()
{
var col = DataGrid.Columns[i];

ColumnDefinitions.Add(col.ColumnDefinition);
if (i > ColumnDefinitions.Count - 1)
{
ColumnDefinitions.Add(col.ColumnDefinition);
}
else if (ColumnDefinitions[i] != col.ColumnDefinition)
{
ColumnDefinitions[i] = col.ColumnDefinition;
}

if (!col.IsVisible)
{
Expand All @@ -92,6 +98,11 @@ private void CreateView()
SetColumn((BindableObject)cell, i);
Children.Add(cell);
}

for (var i = ColumnDefinitions.Count - 1; i > DataGrid.Columns.Count - 1; i--)
{
ColumnDefinitions.RemoveAt(i);
}
}

private void SetStyling()
Expand Down
Loading