How to display sum of 2 cell values in another cell and autorefresh it as cell values change in wxpython grid?

StackOverflow https://stackoverflow.com/questions/20519669

Question

I have a wx.grid with size 1*3 (1 row, 3 columns). Cell 1*1 has value 3, cell 1*2 has value 5 and I want cell 1*3 to display sum of the other cells (3 + 5 = 8). And I want cell 1*3 to autoupdate its value as cell 1*1 and cell 1*2 changes. How to do this wit wxpython grid?

Was it helpful?

Solution

You will need to catch a cell related events. I would recommend EVT_GRID_EDITOR_HIDDEN as that event fires after you have left a cell where you had double-clicked it to start an edit. You could also use EVT_GRID_CELL_CHANGE, although just because you changed cells doesn't mean you did an edit.

Either way, in the event handler, you would grab the first two cell values, sum them and insert them into the third cell.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top