wxGrid: change cell value in EVT_GRID_CELL_CHANGING

391 views
Skip to first unread message

Fulvio Senore

unread,
Dec 10, 2010, 11:51:18 AM12/10/10
to wx-...@googlegroups.com
I am working at a program that uses wxGrid in some dialogs and now I
need a new feature.

I want to let the user type some letters in a cell (for example for a
customer name), then press TAB: the program will validate the entered
text and complete it to an existing name.
So if the user types "SMIT" the program might change it to "SMITH,
JOHN", for example, or show an error message if the name is unknown.

It looks like the right place for this code is in the
EVT_GRID_CELL_CHANGING event handler. I can get the typed text with
event.GetString() and I can veto if the text is not correct.
The problem is that I need to change the cell text from within this
event handler, to set the text to its expanded form.

I have looked at the source code and it looks like a rather simple way
would be to let the event handler code change the cell text by setting
the new value using event.SetString(). There is a symmetry with the
existing GetString() way to get the cell code so it looks a good
solution from an end user viewpoint.

The code modifications should be rather limited, so I should be able to
implement it and submit a patch.

Are you interested in adding such a feature to wxWidgets, or do you
think that it is not worth doing it?

Do you think that there is a better way to accomplish what I am looking for?

Best regards

Fulvio Senore

Vadim Zeitlin

unread,
Dec 10, 2010, 3:44:11 PM12/10/10
to wx-...@googlegroups.com
On Fri, 10 Dec 2010 17:51:18 +0100 Fulvio Senore <mai...@fsoft.it> wrote:

FS> I want to let the user type some letters in a cell (for example for a
FS> customer name), then press TAB: the program will validate the entered
FS> text and complete it to an existing name.
FS> So if the user types "SMIT" the program might change it to "SMITH,
FS> JOHN", for example, or show an error message if the name is unknown.
FS>
FS> It looks like the right place for this code is in the
FS> EVT_GRID_CELL_CHANGING event handler.

I'm not sure why is this the right place... How is it related to pressing
TAB? This event could be generated quite independently of it.

FS> I can get the typed text with event.GetString() and I can veto if the
FS> text is not correct. The problem is that I need to change the cell text
FS> from within this event handler, to set the text to its expanded form.
FS>
FS> I have looked at the source code and it looks like a rather simple way
FS> would be to let the event handler code change the cell text by setting
FS> the new value using event.SetString(). There is a symmetry with the
FS> existing GetString() way to get the cell code so it looks a good
FS> solution from an end user viewpoint.

AFAIK it doesn't work like this for any other wx control so I'd rather
find some other way to do it. What about vetoing the event and just setting
the cell value to the string you want? If this doesn't work, why?

Regards,
VZ

Fulvio Senore

unread,
Dec 11, 2010, 5:12:19 AM12/11/10
to wx-...@googlegroups.com
Il 10/12/2010 21.44, Vadim Zeitlin ha scritto:

> FS> I have looked at the source code and it looks like a rather simple way
> FS> would be to let the event handler code change the cell text by setting
> FS> the new value using event.SetString(). There is a symmetry with the
> FS> existing GetString() way to get the cell code so it looks a good
> FS> solution from an end user viewpoint.
>
> AFAIK it doesn't work like this for any other wx control so I'd rather
> find some other way to do it. What about vetoing the event and just setting
> the cell value to the string you want? If this doesn't work, why?

Thank you for suggesting this solution, it works perfectly. I did not
know that changed values in the underlying table immediately show up in
the grid. My knowledge of wxGrid is still limited, but I hope that it
will improve as I keep using it.

Fulvio Senore

Reply all
Reply to author
Forward
0 new messages