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

Mac: Reload data when selection changes in TreeGridView the same as it does for GridView #2543

Merged
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
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
Loading