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

Fix nth child selector in data grid header #15482

Merged
merged 4 commits into from
May 13, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/Avalonia.Controls.DataGrid/DataGridColumnCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace Avalonia.Controls
{
internal class DataGridColumnCollection : ObservableCollection<DataGridColumn>
{
private readonly Dictionary<int, int> _columnsMap = new Dictionary<int, int>();
private readonly DataGrid _owningGrid;

public DataGridColumnCollection(DataGrid owningGrid)
Expand Down Expand Up @@ -280,12 +279,10 @@ internal void EnsureVisibleEdgedColumnsWidth()
VisibleStarColumnCount = 0;
VisibleEdgedColumnsWidth = 0;
VisibleColumnCount = 0;
_columnsMap.Clear();

for (int columnIndex = 0; columnIndex < ItemsInternal.Count; columnIndex++)
{
var item = ItemsInternal[columnIndex];
_columnsMap[columnIndex] = item.DisplayIndex;
if (item.IsVisible)
{
VisibleColumnCount++;
Expand All @@ -299,11 +296,6 @@ internal void EnsureVisibleEdgedColumnsWidth()
}
}

internal int GetColumnDisplayIndex(int columnIndex)
{
return _columnsMap.TryGetValue(columnIndex, out var displayIndex) ? displayIndex : -1;
}

internal DataGridColumn GetColumnAtDisplayIndex(int displayIndex)
{
if (displayIndex < 0 || displayIndex >= ItemsInternal.Count || displayIndex >= DisplayIndexMap.Count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ internal DataGridRow OwningRow
int IChildIndexProvider.GetChildIndex(ILogical child)
{
return child is DataGridCell cell
? OwningGrid.ColumnsInternal.GetColumnDisplayIndex(cell.ColumnIndex)
? cell.OwningColumn?.DisplayIndex ?? -1
: throw new InvalidOperationException("Invalid cell type");
}

bool IChildIndexProvider.TryGetTotalCount(out int count)
{
count = OwningGrid.ColumnsInternal.VisibleColumnCount;
count = Children.Count - 1; // Adjust for filler column
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ internal DataGrid OwningGrid
int IChildIndexProvider.GetChildIndex(ILogical child)
{
return child is DataGridColumnHeader header
? OwningGrid.ColumnsInternal.GetColumnDisplayIndex(header.ColumnIndex)
? header.OwningColumn?.DisplayIndex ?? -1
: throw new InvalidOperationException("Invalid cell type");
}

bool IChildIndexProvider.TryGetTotalCount(out int count)
{
count = OwningGrid.ColumnsInternal.VisibleColumnCount;
count = Children.Count - 1; // Adjust for filler column
return true;
}

Expand Down