If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
1) also having text in the same cell
2) when I click one check box, all the other check boxes that have the *same* string also get selected
would this be possible, or is it too much to ask to wxwidgets ?
having text on the same cell could be skipped, an option would be to have the text in another column;
but the ability to have all the other check boxes selected (that have the same text ) remains
pvn wrote: ↑Thu Jul 30, 2020 1:38 am
2) when I click one check box, all the other check boxes that have the *same* string also get selected
You can catch the appropriate event and then go thru all cells and check/uncheck the check box.
You just need to test how efficient it will be, depending on the number of cells.
pvn wrote: ↑Thu Jul 30, 2020 1:38 am
would this be possible, or is it too much to ask to wxwidgets ?
having text on the same cell could be skipped, an option would be to have the text in another column;
but the ability to have all the other check boxes selected (that have the same text ) remains
Hi,
Are they going to be in 1 row/1 column or it will be intermixed with other ones?
Anyway:
event.GetCol() - should give you the column where the click occur
event.GetRow() - should give ou the row
grid->GetCellEditor() - should give you the editor assigned to the cell
Cast it as appropriately and check the pointer validity.
But as I said - it all needs to be tested so that you don't lose the performance.
Maybe it is better to use wxDVC or wxListCtrl in report/virtual mode?
the usage is like in the image: I want to add a check box to all the blue rows in the column;
I will give it a try to a custom renderer like in the grid demo
thanks
You need a wxGridCellBoolRenderer like in the sample.
In order to change the state of the checkbox, set the value of the cell: "0" for unchecked, "1" for checked
The first time I used checkboxes in a wxGrid I experienced I had to click twice to check or uncheck the checkbox. The first click was to set the cell in focus, the second to actually select the checkbox control in the cell.
However Julian Smart sent me the code to actually make the checkbox work with a single click. Maybe this proves to be useful for you too.
// Handling a single check on the first column-cells of the grid where checkboxes have been
// displayed by using the boolean editor/renderer. This to avoid a dubbel-click to select
// or deselect the checkbox. Courtesy to Julian Smart.
void tcGDoc::OnGridCheck(wxGridEvent& event)
{
bool bSelected;
short nAkls, nCkls, nArtAkls;
int nCol, nRow, nGRow, nPos;
long nAantal;
wxString sTxt, sAkls, sCkls, sVpath, sSelVpath;
wxGrid *hGrid;
nCol = event.GetCol();
nRow = event.GetRow();
if (nCol == 0)
{
hGrid = XRCCTRL(*this, "DOCD_ARTCOMPONENTS", wxGrid);
sTxt = hGrid->GetCellValue(nRow, 0);
if ((sTxt.IsEmpty()) || (sTxt.Cmp("0") == 0))
{
hGrid->SetCellValue(nRow, 0, "1");
bSelected = true;
}
else
{
hGrid->SetCellValue(nRow, 0, "");
bSelected = false;
}
hGrid->Refresh();
return;
}
event.Skip();
}
Normally wxGridCellEditor shows some UI control allowing the user to edit
the cell, but starting with wxWidgets 3.1.4 it's also possible to define
"activatable" cell editors, that change the value of the cell directly when
it's activated (typically by pressing Space key or clicking on it).