ETO ListBox with DataStore and custom items (list of <T>)

Hi @curtisw, @dale,

i am creating a Eto.Forms.ListBox which uses a DataStore for its list items as shown here. However my list is not a list of strings but a list of class instances. The class name is “Fruit”. The listbox DataStore seems to accept my list but each list item is displayed in the listbox like this:

<__main__.Fruit instance at 0x0000000000000085>

Each class instance has a property “Name”. How do i tell Eto to use “Name” as Eto.Forms.ListItem.Text ?

In Windows forms this is done like this:

self._listBox1.DataSource = MyListOfFruit
self._listBox1.DisplayMember = "Name"

_
c.

1 Like

Hi @clement,

Does adding a ToString member to your Fruit class help?

– Dale

Hi @dale,

sorry no, it still displays list items like this using a Text property:

image

The ToString() hint i’ve googled as well and found that i can change how a class instance is printed using __repr__ (which is problably equal to the ToString() solution) and it then shows the ListBox items using that text output. A better way i’ve found was to manually set the ListBoxItem.Text and attach the class instance as Tag to the ListBoxItem

Is it a bug that i cannot set a DisplayMember like in WinForms ?

_
c.

No, Eto in Rhino 6 for Windows uses WPF.

In C#, you’d set the data store to some view model and then you’d bind the appropriate property to the list box’s ItemTextBinding member. I’m pondering how to do this in Python.

– Dale

Hi @dale, of course but i meant that i cannot define the Key / Text which is used freely.

I’ve found in the Eto ListItem docs the Remarks to use a TextBinding/KeyBinding but have no clue how ?

_
c.

I’ve already started a sample - I’ll share it tomorrow (hopefully)…

– D

1 Like

Hi @clement,

Let me know if this is helpful.

https://github.com/mcneel/rhino-developer-samples/blob/6/rhinopython/SampleEtoListBoxDialog.py

– Dale

1 Like

Hi @dale, thanks for the example, i am trying wrap my head around that code :wink:

_
c.