Eto - TreeGridView - basic questions

Hi @curtisw, @dale,

i’ve collected a few basic questions for using the Eto.Forms.TreeGridView:

How can i control to which column the litle black triangle is assigned to collapse / expand a TreeGridItem ? For example, Rhino’s built in Layer dialog always shows that triangle in the “Name” column, even when a column (here the current layer indicator hook) is displayed in a column before the “Name” column:

grafik

If i try to build my TreeGridView with the same column order and layer structure as shown above, the triangle is always assigned to the first column and therefore i cannot see any indentation in the “Name” column:

grafik

I’ve tried to add and swap columns after loading but this did not work. However if i make the “Name” column the first column, i can manually move the “hook” column and the “Name” column stays the one which is expandable / collapsable.
_

How do i assign custom text colors to individual TreeGridView items / or cells ? I’ve created (custom) items of type TreeGridItem and the “Name” column uses an ImageTextCell with bindings for the text and image. For some of these cells, i would like to use a different text color. I’ve tried to access the color by doing this:

cell = Eto.Forms.ImageTextCell()
cell.ControlObject.Foreground.Color = Eto.Drawing.Colors.Red

but i get an error:

Expected Color, got Color

_

How to select items / rows in the TreeGridView programmatically and how can i flag individual items / rows as not beeing selectable by the user ?

thanks,
c.

The expand/collapse image is always in column 0 as the grid is constructed. This is also true of the Layers panel control (although it doesn’t use Eto.)

Subscribe to the grid’s CellFormatting event:

control.CellFormatting += (sender, e) =>
{
  e.Font = font;
  e.BackgroundColor = e.Row % 2 == 0 ? Colors.Blue : Colors.LightBlue;
  e.ForegroundColor = e.Row % 2 == 0 ? Colors.Lime : Colors.Yellow;
};

Using the Grid.SelectedRows property is one way.

You might try subscribing to the Grid.SelectedRowsChanged event and, when triggered, unselect what was selected.

– Dale

1 Like

Thank you @dale for your reply.

I have my “Name” column at index 0 too, the “Current” column has index 1. I can move the “Current” column if the TreeGridView has AllowColumnReordering enabled by hand to get what i want, the expand/collapse image stays attached to the “Name” column. However if i try to do the same programmatically, the expand/collapse image is not changing it’s column. I do the column swap this way:

self.tree.Columns.Move(0, 1)

Here is a small gif showing the manual column swap and the programmatic way:

ColumnReordering

_

This worked ! I’ve found a small drawback when changing cell colors though, the color changes are persistent, even when an item is selected the color is preserved… But i was able to set the current layer font to bold using this event.

_

This turned out to be the hardest nut. I need to find selected item(s) which i could receive using grid.SelectedItems. But how can i find the row (index) of an item and vice versa without iterating over all items/rows ?

_

One more question: Rhino’s build in layer dialog hides the column header text if the column width is very narrow. How can i do the same with the TreeGridView ? I have this look atm:

grafik

thanks,
c.

Hi @dale and @curtisw,

i’m not sure but i think i found a possible bug in OnCellClick and OnCellDoubleClick events applied to a TreeGridView or GridView. The .GridColumn property of the GridCellMouseEventArgs appears to be wrong after columns have been reordered by the user.

To reproduce, please try out below example. If you double click a cell, e.Column and e.GridColumn is printed as expected. Once the Friday column is dragged before the Monday column, a double click on a cell in the Friday column still gives Monday for e.GridColumn. Shouldn’t this return Friday instead ?

OnCellDoubleClickBug.py (2.2 KB)

_
c.

Hi @clement,

When creating a GridColumn, the the ID property that identifies your column. Then in a click handler, check the ID to verify the column that was clicked.

if e.Column.ID == "Color":
    # todo...

– Dale

Hi @dale, i am sorry but assigning the ID property to the GridColumn is exactly what i did to demonstrate the problem. It is printed (the wrong value) to the commandline in brackets. Btw. e.Column is an index which gives 0 but i expect 4 after dragging Friday before Monday.

Please try this to print all possible variations:

msg = "OnCellDoubleClick:  Column={}  GridColumn.ID={}  Row={}  day={}"
print msg.format(e.Column, e.GridColumn.ID, e.Row, self.Columns[e.Column])

_
c.

Hi @clement,

Does the attached work any better?

OnCellDoubleClickBug.py (2.0 KB)

– Dale

1 Like

Hi @dale, yes thanks. OnMouseDoubleClick is what i used as a workaround too. Would you agree that OnCellClick and OnCellDoubleClick do not work as expected with reordered columns ?

EDIT: It seems OnCellClick has e.Location property too so i can use GetCellAt(e.Location) as you did.
_
c.

Hey @clement,

The API’s and functionality for GridView/TreeGridView column reordering are not quite complete or fully functional. There needs to be some sort of Order property for GridColumn, so the actual order in the GridView.Columns list would not change, and the Order would specify how they appear when presented.

I’ve logged RH-58995 to fix this.

1 Like

Is there an update on this?

Kindest
Christian

@Christian_Hartz, ah yes, this should land in 7.19 as I did it for some other work and forgot to update that issue. Thanks for the ping!

BTW, the new property is GridColumn.DisplayIndex, and a new event Tree/GridView.ColumnOrderChanged to track when a user changes the order.

1 Like

Hi @curtisw,

is there a way now to control which column gets the litle triangle to collapse / expand ?

_
c.

Hey @clement,

No, the expand/collapse images always appear in the first column.

– Dale

@clement Actually, with the new GridColumn.DisplayIndex, you can set the expand/collapse column to visually appear on a different column. It will always be the first column in the Grid.Columns collection, but if you set its display index to, say, 2, then the columns with DisplayIndex 0 and 1 will appear before it. This is only available in 7.19 or later.

Thank you @dale and @curtisw. I will try how i can set GridColumn.DisplayIndex programmatically so the expand/collapse marker changes properly once the user rearranges the collumns.

_
c.

RH-58995 is fixed in Rhino 7 Service Release 19