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