How would you get current selection from a wx.grid.GridCellChoiceEditor() ?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How would you get current selection from a wx.grid.GridCellChoiceEditor() ?

steve
Hi,

I created a wx.grid and set a cell's editor to wx.grid.GridCellChoiceEditor so that it will display a drop down combo box to enter values.

sampleList = ["Value_1", "Value_2"]

self.choice_editors = {}

self.choice_editors["new"] = {}
self.choice_editors["new"]["editor_1"] = 
wx.grid.GridCellChoiceEditor(sampleList)

self.my_grid.SetCellEditor(0, 0, self.choice_editors["new"]["editor_1"])




When I try to get the current value of the cell that has GridCellChoiceEditor:


selection= self.choice_editors["new"]["editor_1"].GetValue()


the program crashes with following error:


Process finished with exit code -1073740771 (0xC000041D)



What is the proper way of getting values from a wx.grid.GridCellChoiceEditor()?

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/063e9f73-554f-4455-b4ef-9bd0839269fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: How would you get current selection from a wx.grid.GridCellChoiceEditor() ?

GadgetSteve

The answer is that you get the value from the cell, where it should be set by your editor. From the demo:

 

 

 

    def ApplyEdit(self, row, col, grid):

        """

        This function should save the value of the control into the

        grid or grid table. It is called only after EndEdit() returns

        a non-None value.

        *Must Override*

        """

        self.log.write("MyCellEditor: ApplyEdit (%d,%d)\n" % (row, col))

        val = self._tc.GetValue()

        grid.GetTable().SetValue(row, col, val) # update the table

 

        self.startValue = ''

        self._tc.SetValue('')

 

The reason that you get a crash is that once the editor doesn’t have a value once the edit is done as the control is not the editor but rather the editor’s choice control, (a text control called tc in the demo).

 

Hope that helps.

 

Gadget Steve

 

From: [hidden email] <[hidden email]> On Behalf Of steve
Sent: 17 July 2019 18:23
To: wxPython-users <[hidden email]>
Subject: [wxPython-users] How would you get current selection from a wx.grid.GridCellChoiceEditor() ?

 

Hi,

 

I created a wx.grid and set a cell's editor to wx.grid.GridCellChoiceEditor so that it will display a drop down combo box to enter values.

 

sampleList = ["Value_1", "Value_2"]

 

self.choice_editors = {}

self.choice_editors["new"] = {}
self.choice_editors["new"]["editor_1"] = wx.grid.GridCellChoiceEditor(sampleList)

self.my_grid.SetCellEditor(0, 0, self.choice_editors["new"]["editor_1"])




When I try to get the current value of the cell that has GridCellChoiceEditor:


selection= self.choice_editors["new"]["editor_1"].GetValue()


the program crashes with following error:


Process finished with exit code -1073740771 (0xC000041D)



What is the proper way of getting values from a wx.grid.GridCellChoiceEditor()?

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/063e9f73-554f-4455-b4ef-9bd0839269fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/VI1PR03MB4479FF0A9FE141922783A26E9BC90%40VI1PR03MB4479.eurprd03.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How would you get current selection from a wx.grid.GridCellChoiceEditor() ?

steve
I don't understand. How would you get the string value from the grid cell that has a choice editor? Could you please write the specific code for this?

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/f059e538-80e0-4fb6-adb5-c19d387835cb%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

RE: How would you get current selection from a wx.grid.GridCellChoiceEditor() ?

GadgetSteve
Your editor is called with cell coordinates (row, col, grid) within the grid, (because the editor can apply to more than one cell, e.g. a column of cells), and should on ending editing call ApplyEdit which should set the value of the cell at (row, col) within the grid. To get the value you can use your_grid.GetCellValue(row, col) to get the new value of the cell that you were editing! The demo can be very helpful - https://github.com/wxWidgets/wxPython/blob/master/demo/GridCustEditor.py specifically - as can the documents https://wxpython.org/Phoenix/docs/html/wx.grid.Grid.html#wx.grid.Grid.GetCellValue 

-----Original Message-----
From: [hidden email] <[hidden email]> On Behalf Of steve
Sent: 18 July 2019 12:23
To: wxPython-users <[hidden email]>
Subject: Re: [wxPython-users] How would you get current selection from a wx.grid.GridCellChoiceEditor() ?

I don't understand. How would you get the string value from the grid cell that has a choice editor? Could you please write the specific code for this?

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/f059e538-80e0-4fb6-adb5-c19d387835cb%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/VI1PR03MB44794C7487F89F0D2AF1A9859BC80%40VI1PR03MB4479.eurprd03.prod.outlook.com.