All you do is:
self.GetCellVal ue(row, column)
Where self is a wxGrid class instance.
Sample class from working program:
class SimpleGrid(wxGr id): ##, wxGridAutoEditM ixin):
def __init__(self, parent):
wxGrid.__init__ (self, parent, -1)
#
# Get shortcuts to some editors for different types of cells
#
bEditor=wxGridC ellBoolEditor()
bRenderer=wxGri dCellBoolRender er()
tEditor=wxGridC ellTextEditor()
tRenderer=wxGri dCellStringRend erer()
fEditor=wxGridC ellFloatEditor( )
fRenderer=wxGri dCellFloatRende rer()
fRenderer.SetPr ecision(2)
#
# Define and set the column sizes and labels
#
# Display
#--Column Heading, Width, Alignment,read-only, editor, renderer
self.columndefs =(
("?", 20, wxALIGN_LEFT, false, bEditor, bRenderer),
("Cust#", 50, wxALIGN_LEFT, true, tEditor, tRenderer),
("Cust Name", 180, wxALIGN_LEFT, true, tEditor, tRenderer),
("Reference" , 100, wxALIGN_LEFT, true, tEditor, tRenderer),
("DocType", 50, wxALIGN_CENTRE, true, tEditor, tRenderer),
("Inv. #", 75, wxALIGN_CENTRE, true, tEditor, tRenderer),
("InvDate", 60, wxALIGN_CENTRE, true, tEditor, tRenderer),
("L#", 35, wxALIGN_CENTRE, true, tEditor, tRenderer),
("Item #", 65, wxALIGN_CENTRE, true, tEditor, tRenderer),
("Description", 300, wxALIGN_LEFT, false, tEditor, tRenderer),
("Qty", 50, wxALIGN_RIGHT, false, tEditor, tRenderer),
("Price", 50, wxALIGN_RIGHT, true, fEditor, fRenderer),
("Cost", 50, wxALIGN_RIGHT, true, fEditor, fRenderer),
("OMMC?", 60, wxALIGN_CENTRE, false, tEditor, tRenderer),
("OMMC $", 70, wxALIGN_RIGHT, false, tEditor, tRenderer),
("S#", 35, wxALIGN_CENTRE, false, tEditor, tRenderer),
("Serial #'s", 300, wxALIGN_LEFT, false, tEditor, tRenderer)
)
self.columncoun t=len(self.colu mndefs)
self.CreateGrid (0, self.columncoun t)
#
# Set column widths
#
map(self.SetCol Size, range(self.colu mncount),
[a[1] for a in self.columndefs])
#
# Set custom column labels
#
map(self.SetCol LabelValue, range(self.colu mncount),
[a[0] for a in self.columndefs])
#
# Sheet will toggle between these two colors on change of invoice
number
#
# LightGray
self._backgroun dcolors=[wxWHITE,"#CCCCC C"]
self._toggleBGC =0
#
# Register event handlers
#
#EVT_GRID_CELL_ LEFT_DCLICK(sel f, self.OnCellLeft DClick)
#EVT_GRID_CELL_ LEFT_CLICK(self , self.OnCellLeft Click)
#EVT_GRID_CELL_ RIGHT_CLICK(sel f, self.OnCellRigh tClick)
#EVT_GRID_RANGE _SELECT(self, self.OnRangeSel ect)
EVT_GRID_CELL_C HANGE(self, self.OnCellChan ge)
return
def OnCellChange(se lf, evt):
row=evt.GetRow( )
col=evt.GetCol( )
#
# Special handlers for some columns
#
if col == 13:
self.SetCellVal ue(row, col, self.GetCellVal ue(row,col).upp er())
if self.GetCellVal ue(row, col) not in ("Y","N"):
self.SetCellVal ue(row, col, "Y")
if self.GetCellVal ue(row, col) == "N":
self.SetCellTex tColour(row, 13, wxBLACK)
if self.GetCellVal ue(row, col) == "Y" and \
self.GetCellVal ue(row, 14) == "0.00":
self.SetCellTex tColour(row, col, wxRED)
elif col == 14:
if self._trace: self.logf.write lines("T","Col= 14 functions")
equation=self.G etCellValue(row , col)
if equation[0] == "=": equation=equati on[1:]
try: value="%.2f" % eval(equation)
except: value="0.00"
self.SetCellVal ue(row, col, value)
if value != "0.00" and self.GetCellVal ue(row, 13) == "Y":
self.SetCellTex tColour(row, 13, wxBLACK)
elif value == "0.00" and self.GetCellVal ue(row, 13) == "Y":
self.SetCellTex tColour(row, 13, wxRED)
elif col == 15:
self.SetCellVal ue(row, col, self.GetCellVal ue(row,col).upp er())
if self.GetCellVal ue(row, col) not in ("Y","N"):
self.SetCellVal ue(row, col, "Y")
if self.GetCellVal ue(row, col) == "N":
self.SetCellTex tColour(row, col, wxBLACK)
self.SetCellTex tColour(row, 9, wxBLACK)
if self.GetCellVal ue(row, col) == "Y" and \
not self.GetCellVal ue(row, 16):
self.SetCellTex tColour(row, col, wxRED)
self.SetCellTex tColour(row, 9, wxRED)
else: return
self.ForceRefre sh()
return
Hope it helps. I pretty much got this from the wxWindows demos
that come with standard installation.
Regards,
Larry Bates
Syscon, Inc.
"matthiasja nes" <ma***********@ gmx.net> wrote in message
news:d5******** *************** ***@posting.goo gle.com...
dear all,
I just need a little help.
could anyone give real code example (simple) how to read the value of
a grid cell.
i could not figure it out and really would like to do a simple
spreadsheet application in wxpython (my first try with wxpython gui)
so, if any one knows just how to read the value of a cell - a real
working example would be greatly appriciated
Matthias Janes