Eto combobox in gridview (Python)

Trying to show a combobox in a gridview:

import Eto.Drawing as drawing
import Eto.Forms as forms

form = forms.Dialog()
form.Title = "test combobox in gridview"
form.ClientSize = drawing.Size(800, 600)
form.Resizable = False

comboMaterialType = forms.ComboBox(DataStore = ['Wood', 'Plastic'], SelectedIndex = 0)

dataStoreRow1 = ['Surface 01: Front_Planes', comboMaterialType]
dataStoreRow2 = ['Surface 02: Front_Edges', comboMaterialType]

gridOption1 = forms.GridView()
gridOption1.ShowHeader = False
gridOption1.DataStore = (dataStoreRow1, dataStoreRow2)
gridOption1.Columns.Add(forms.GridColumn(Editable = False, DataCell = forms.TextBoxCell(0)))
gridOption1.Columns.Add(forms.GridColumn(Editable = True, DataCell = forms.ComboBoxCell(1)))

layout = forms.DynamicLayout(DefaultSpacing = drawing.Size(5, 5), Padding = drawing.Padding(10))
layout.AddRow(gridOption1)

form.Content = layout
form.ShowModal()

The combobox is there but shows empty. You don’t see it immediately because the content is not shown.
When you click the combobox the first time (just behind the text), you have to click it a second time to see it’s a dropdown and a third time to actually see the dropdown list, which still shows empty:

eto_empty_combobox

What am I doing wrong?

PS: it’s a pity the documentation about Eto is so fragmented and in different languages. As I am not aquainted with C++ or C#, I can’t understand the code or translate it to Python …

Hi @dick.lelyveld,

Thanks for the inquiry and apologies for the late response. What you need to do is set the DataStore of the ComboBoxCell instead of using a ComboBox as the value for each cell. Something like this should work:

import Eto.Drawing as drawing
import Eto.Forms as forms

form = forms.Dialog()
form.Title = "test combobox in gridview"
form.ClientSize = drawing.Size(800, 600)
form.Resizable = False

comboMaterialType = forms.ComboBoxCell(1)

comboMaterialType.DataStore = ['Wood', 'Plastic']

dataStoreRow1 = ['Surface 01: Front_Planes', 'Wood']
dataStoreRow2 = ['Surface 02: Front_Edges', 'Plastic']

gridOption1 = forms.GridView()
gridOption1.ShowHeader = False
gridOption1.DataStore = (dataStoreRow1, dataStoreRow2)
gridOption1.Columns.Add(forms.GridColumn(Editable = False, DataCell = forms.TextBoxCell(0)))
gridOption1.Columns.Add(forms.GridColumn(Editable = True, DataCell = comboMaterialType))

layout = forms.DynamicLayout(DefaultSpacing = drawing.Size(5, 5), Padding = drawing.Padding(10))
layout.AddRow(gridOption1)

form.Content = layout
form.ShowModal()

Have you seen the Eto Controls in Python page in Rhino’s documentation? Please take a look and let us know if we are missing anything.

Thanks very much @curtisw!
Now I understand :slight_smile:

About the documentation, I will try to compile a list of items I had problems with to understand. Maybe you can use that to add to the documentation.
At the moment I’m not busy with Rhino Python, but when I do again, I will dedicate some time to it.

Kind regards, Dick

Hi @curtisw , thanks for this example for ComboBoxCell.

I am trying to use ComboBoxCell, but it seems its value cannot cannot be changed:
2020-03-27-20-46-25

Could you please let me know if I am missing anything? Here is code I am just using your example to illustrate this issue.

            var collection = new List<List<string>>()
                {
                    new List<string> { "srf1", "Plastic" },
                    new List<string> { "srf2", "Wood" }
                };

            var gridOption1 = new GridView() { DataStore = collection, AllowMultipleSelection = true };
            gridOption1.Columns.Add(new GridColumn
            {
                Editable = false,
                DataCell = new TextBoxCell(0),
                HeaderText = "Name"
            });

            var comboMaterialType = new ComboBoxCell(1);
            comboMaterialType.DataStore = new List<string>() { "Wood", "Plastic" };
            gridOption1.Columns.Add(new GridColumn
            {
                Editable = true,
                DataCell = comboMaterialType,
                HeaderText = "Material"
            });

I am having the same issues in RhinoPyhton. I found that using the mouse scroll-wheel does change the ComboBoxCell content during editing, but using a mouse click I get the same behavior as @mingo1214 (unable to expand the ComboBoxCell dropdown)

My example code is below:

import Rhino.UI
import rhinoscriptsyntax as rs
import Eto.Forms as forms
import Eto.Drawing as drawing


class EtoGridView(forms.Dialog[bool]):

	# Initialize
	def __init__(self):
		
		# Default dialogue box
		self.Title = "Gridview Test"
		self.Padding = drawing.Padding(10)
		self.Resizable = True
		
		 #Create Gridview
		self.m_gridview = forms.GridView()
		self.m_gridview.ShowHeader = True
		self.m_gridview.DataStore = (['Row 1', 'Option 1'],['Row 2','Option 2'], ['Row 3','Option 3'])
		self.m_gridview.Width = 300

		column1 = forms.GridColumn()
		column1.HeaderText = 'Column 1'
		column1.Editable = False
		column1.DataCell = forms.TextBoxCell(0)
		self.m_gridview.Columns.Add(column1)

		column2 = forms.GridColumn()
		column2.HeaderText = 'Column 2'
		column2.Editable = True
		column2.DataCell = forms.ComboBoxCell(1)
		column2.DataCell.DataStore = ['Option 1', 'Option 2', 'Option 3', 'Option 4']
		self.m_gridview.Columns.Add(column2)


		# Button OK
		self.DefaultButton = forms.Button(Text = "OK")
		self.DefaultButton.Click += self.OnOKButtonClick


		# Create the layout of the form
		layout = forms.DynamicLayout()
		layout.Spacing = drawing.Size(5,5)
		layout.AddRow(self.m_gridview)
		layout.AddRow(self.DefaultButton)
		self.Content = layout

	# OK Button Handler
	def OnOKButtonClick(self, sender, e):
		self.Close(False)


# Main script
if __name__ == "__main__":
	dialog = EtoGridView()
	rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)

Was an answer ever found for the selection problem? I have the same issue.

Eric

Hi @curtisw, your example does not seem to work over here using Win7 and Rhino 6 SR25. I see the combobox once clicked in the gridview but it does not show the values in a dropdown.

It is a good start but would be even more helpful if these examples are complete and ready to run for new users from the built in python editor. It seems that someone just tried out various Eto controls and made screenshots from a dialog with the same title but never saved the complete results.
_
c.

1 Like

Has anyone had a chance to solve this?

Hi @etiennekasteel,

Rather than using gridview, I ended up using table layout for these sorts of layout.
Unfortunately you lose the abilities to add, delete and move rows, but if you have a specified set of data going in, you at least get consistent results.

@curtisw , Reviving this topic as it is still a problem in v7.4. The problem as described by @mingo1214 persists. I’ve spent quite a bit of time digging into this and it seems to stem from the combobox not getting proper focus. The first time you try and use the combobox via drop down it doesn’t work, but if you try it again without clicking on something else it will work. Similarly, if you select the combobox without activating the drop down first and then click the drop down it will function as expected. As mentioned by @etiennekasteel , selecting the combobox and using the scroll wheel or arrow keys to select other options also works. Happy to start a new thread but thought it would be good to continue it here.

Thank you for the update. I may add that the same problem holds for the “checkbox” field in a gridview.

Depending on the focus the checkbox may or may not correctly trigger the callback. A workaround here is to select the correct cell and then use the “space-bar” to change the checkbox status and confirm with “Enter-key”. I have found this always triggers the callback correctly.

Hey everyone,

I just looked into this (thanks for the ping) and indeed something broke on our end, apologies! I’ve created RH-63922 to fix that up.

1 Like

Will this also be pushed to Rhino 6?

@etiennekasteel that wasn’t the plan, but I can look at back porting it if necessary.

That would be awesome, we are using an eto application with Rhino 6.

Ok no problem, I’ll look into it!

Hi I noticed the bug was fixed in Rhino 7 already it now works like a charm. Any news on when there will be a fix for Rhino 6?

@etiennekasteel The fix should be in 6.35.21116.15001 or later. Please let me know if you’re still running into problems with that release.

I just tried it out on 6.35.21222.17001 with no luck, bug is still there. Rhino 7 version 7.10.21236.11001 works well.

@curtisw any news on a fix in Rhino 6. Recently tried again in version 6.35.21222.17001 with no luck…