Skip to content

Commit

Permalink
Merge pull request #2543 from cwensley/curtis/mac-treegridview-reload…
Browse files Browse the repository at this point in the history
…-when-selection-changes

Mac: Reload data when selection changes in TreeGridView the same as it does for GridView
  • Loading branch information
cwensley authored Aug 23, 2023
2 parents 4e55c43 + 25cf567 commit f5c1537
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/Eto.Mac/Forms/Controls/TreeGridViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,32 @@ public override bool ShouldEditTableColumn(NSOutlineView outlineView, NSTableCol
return true;
}

NSIndexSet previouslySelected;
public override void SelectionDidChange(NSNotification notification)
{
var h = Handler;
if (h == null)
return;

if (h.skipSelectionChanged > 0)
return;

// didn't start a drag (when this was set), so clear this out when the selection changes
h.CustomSelectedItems = null;

h.Callback.OnSelectionChanged(h.Widget, EventArgs.Empty);
var item = h.SelectedItem;
if (!ReferenceEquals(item, lastSelected))
if (h.SuppressSelectionChanged == 0)
{
h.Callback.OnSelectedItemChanged(h.Widget, EventArgs.Empty);
lastSelected = item;
h.Callback.OnSelectionChanged(h.Widget, EventArgs.Empty);
var columns = NSIndexSet.FromNSRange(new NSRange(0, h.Control.TableColumns().Length));
if (previouslySelected?.Count > 0)
h.Control.ReloadData(previouslySelected, columns);
var selected = h.Control.SelectedRows;
if (selected?.Count > 0)
h.Control.ReloadData(selected, columns);
previouslySelected = selected;
}
}

public override void ItemDidCollapse(NSNotification notification)
{
var h = Handler;
Expand Down Expand Up @@ -243,7 +251,8 @@ public override NSView GetView(NSOutlineView outlineView, NSTableColumn tableCol
var cellHandler = colHandler.DataCell.Handler as ICellHandler;
if (cellHandler != null)
{
return cellHandler.GetViewForItem(outlineView, tableColumn, -1, item, (obj, row) => obj != null ? ((EtoTreeItem)obj).Item : null);
var row = (int)outlineView.RowForItem(item);
return cellHandler.GetViewForItem(outlineView, tableColumn, row, item, (obj, row) => obj != null ? ((EtoTreeItem)obj).Item : null);
}
}
return outlineView.MakeView(tableColumn?.Identifier ?? string.Empty, this);
Expand Down

0 comments on commit f5c1537

Please sign in to comment.