# Eto - TreeGridView - basic questions

**URL:** <https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229>\
**Category:** Scripting\
**Tags:** eto, python\
**Created:** [June 1, 2020, 2:18am UTC](https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229 "2020-06-01T02:18:55Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/759176_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [June 1, 2020, 2:18am UTC](https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229/1 "2020-06-01T02:18:55Z")

</div>

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](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/0/7/07d08130e7d610b32fb8386dd7f10d77221214af.png)

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](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/3/f/3ff1c8852973b793649dfac1d4fddfd9803a7e80.png)

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:

```python
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.

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [June 1, 2020, 10:37pm UTC](https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229/2 "2020-06-01T22:37:38Z")

</div>

> [@clement](#):
>
> 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.

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.)

> [@clement](#):
>
> How do i assign custom text colors to individual `TreeGridView` items / or cells ?

Subscribe to the grid’s `CellFormatting` event:

```auto
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;
};

```

> [@clement](#):
>
> How to select items / rows in the `TreeGridView` programmatically

Using the `Grid.SelectedRows` property is one way.

> [@clement](#):
>
> and how can i flag individual items / rows as not beeing selectable by the user ?

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

– Dale

---

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/759176_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [June 2, 2020, 11:40pm UTC](https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229/3 "2020-06-02T23:40:01Z")

</div>

Thank you @dale for your reply.

> [@dale](#):
>
> The expand/collapse image is always in column 0 as the grid is constructed.

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:

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

```

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

 ![ColumnReordering](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/c/1/c10938ab99bc4c8fe74696319c236588257bee5d.gif)

\_

> [@dale](#):
>
> Subscribe to the grid’s `CellFormatting` event:

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.

\_

> [@dale](#):
>
> Using the `Grid.SelectedRows` property is one way.

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](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/6/2/627c9175870dc2409b7923c5436e34ae6007cbbb.png)

thanks,  
c.

---

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/759176_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [June 4, 2020, 2:54am UTC](https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229/4 "2020-06-04T02:54:25Z")

</div>

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](https://discourse.mcneel.com/uploads/short-url/2GduyMWCRjPR4EE74iqHAB15vOI.py) (2.2 KB)

\_  
c.

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [June 4, 2020, 5:20pm UTC](https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229/5 "2020-06-04T17:20:43Z")

</div>

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.

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

```

– Dale

---

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/759176_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [June 4, 2020, 10:14pm UTC](https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229/6 "2020-06-04T22:14:41Z")

</div>

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:

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

```

\_  
c.

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [June 5, 2020, 12:14am UTC](https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229/7 "2020-06-05T00:14:39Z")

</div>

Hi @clement,

Does the attached work any better?

[OnCellDoubleClickBug.py](https://discourse.mcneel.com/uploads/short-url/yRVJZK8QFKUW3fiqBYhvPjXBvL.py) (2.0 KB)

– Dale

---

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/759176_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [June 5, 2020, 12:39am UTC](https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229/8 "2020-06-05T00:39:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![curtisw](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/curtisw/32/769477_2.png) [@curtisw](https://discourse.mcneel.com/u/curtisw)\
**Post date:** [June 8, 2020, 8:16pm UTC](https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229/9 "2020-06-08T20:16:04Z")

</div>

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](https://mcneel.myjetbrains.com/youtrack/issue/RH-58995) to fix this.

---

<div class="post-metadata">

**Author:** ![Christian\_Hartz](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/christian_hartz/32/671954_2.png) [@Christian\_Hartz](https://discourse.mcneel.com/u/Christian_Hartz)\
**Post date:** [April 28, 2022, 2:39pm UTC](https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229/10 "2022-04-28T14:39:55Z")

</div>

Is there an update on this?

Kindest  
Christian

---

<div class="post-metadata">

**Author:** ![curtisw](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/curtisw/32/769477_2.png) [@curtisw](https://discourse.mcneel.com/u/curtisw)\
**Post date:** [April 28, 2022, 7:32pm UTC](https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229/11 "2022-04-28T19:32:15Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/759176_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [May 1, 2022, 1:41pm UTC](https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229/12 "2022-05-01T13:41:32Z")

</div>

Hi @curtisw,

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

\_  
c.

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [May 9, 2022, 6:40pm UTC](https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229/13 "2022-05-09T18:40:45Z")

</div>

Hey @clement,

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

– Dale

---

<div class="post-metadata">

**Author:** ![curtisw](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/curtisw/32/769477_2.png) [@curtisw](https://discourse.mcneel.com/u/curtisw)\
**Post date:** [May 9, 2022, 9:16pm UTC](https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229/14 "2022-05-09T21:16:18Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/759176_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [May 10, 2022, 8:08pm UTC](https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229/15 "2022-05-10T20:08:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![brian](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/brian/32/504171_2.png) [@brian](https://discourse.mcneel.com/u/brian)\
**Post date:** [May 11, 2022, 12:54am UTC](https://discourse.mcneel.com/t/eto-treegridview-basic-questions/103229/16 "2022-05-11T00:54:16Z")

</div>

[RH-58995](https://mcneel.myjetbrains.com/youtrack/issue/RH-58995) is fixed in [Rhino 7 Service Release 19](https://www.rhino3d.com/download/rhino/7/latest)
