I'm new to wxWidgets, but have been using the Visual Component Library (C++ Builder and Delphi) for 18 years.
The VCL's TStringGrid class has an Objects array into which I can store pointers to objects representing information about the contents of a grid row. I generally store objects that have the source data primary key plus state information; I call them "cargo". (I maintain a separate list of these cargo objects for managing their destruction.) When a user performs an action on a row of the grid, I can quickly retrieve the "cargo" from the Objects array and use its information as needed.
Does a comparable concept exist in the wxWidgets list/grid controls? I'm not seeing it in the documentation, but wanted to ask before I build a Rube Goldberg solution of my own!
Thanks,
Kathleen
Want to associate a pointer to object to each row of wxGrid
Re: Want to associate a pointer to object to each row of wxG
You could try to derive your own class from wxGridCellAttr, store additional data in it and use wxGrid::SetRowAttr() to set it for each row.
But i'd suggest to derive your own class from wxGridTableBase and set it with wxGrid::SetTable(). In that case you manage all data yourself, wxGrid just displays it.
But i'd suggest to derive your own class from wxGridTableBase and set it with wxGrid::SetTable(). In that case you manage all data yourself, wxGrid just displays it.
Use the source, Luke!
Re: Want to associate a pointer to object to each row of wxG
wxGrid has many features, included the one you ask for.
http://docs.wxwidgets.org/trunk/overview_grid.html
Data is shown in the window as a string. This means "some one" translates data into a wxString. This is a wxGridCellRenderer.
Data in a cell may be edited by the user, using a wxGridCellEditor.
Cells/rows/cols may have "attributes" such as colour, font, etc. wxGridCellAttr is used for it.
Data, attributes and renderers may be stored in "grid table", derived from wxGridTableBase. In fact, wxGrid uses a default table; but you can tell wxGrid to use your own table.
wxWidgets provides many ready-to-use objects of those types.
In your case, you need to derive a table from wxGridTableBase and add your own relation between cells and your data.
See your/wx/dir/samples/grid for how to achieve it.
http://docs.wxwidgets.org/trunk/overview_grid.html
Data is shown in the window as a string. This means "some one" translates data into a wxString. This is a wxGridCellRenderer.
Data in a cell may be edited by the user, using a wxGridCellEditor.
Cells/rows/cols may have "attributes" such as colour, font, etc. wxGridCellAttr is used for it.
Data, attributes and renderers may be stored in "grid table", derived from wxGridTableBase. In fact, wxGrid uses a default table; but you can tell wxGrid to use your own table.
wxWidgets provides many ready-to-use objects of those types.
In your case, you need to derive a table from wxGridTableBase and add your own relation between cells and your data.
See your/wx/dir/samples/grid for how to achieve it.
Re: Want to associate a pointer to object to each row of wxG
Thank you so much! I'll study the BugsGridTable example in wx/samples/grid to gain understanding.
Kathleen
Kathleen