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.
-
pvn
- Experienced Solver

- Posts: 81
- Joined: Mon Dec 26, 2016 5:21 am
-
Contact:
Post
by pvn » Wed Jul 29, 2020 11:22 pm
I have a grid, and trying to have one column have a check box for all rows with
Code: Select all
wxGridCellAttr* attr;
wxColour clr(51, 172, 255);
attr = new wxGridCellAttr();
attr->SetReadOnly(false);
attr->SetBackgroundColour(clr);
if (1) attr->SetEditor(new wxGridCellBoolEditor());
if (1) attr->SetRenderer(new wxGridCellBoolRenderer());
grid->SetColAttr(0, attr);
the check box displays , but when clicked does not change to checked
running the grid demo, it does
what am I missing here ?
-
ONEEYEMAN
- Part Of The Furniture

- Posts: 4824
- Joined: Sat Apr 16, 2005 7:22 am
- Location: USA, Ukraine
Post
by ONEEYEMAN » Thu Jul 30, 2020 1:20 am
Hi,
What platform? What wx version?
Can you see it in the grid sample?
Thank you.
-
pvn
- Experienced Solver

- Posts: 81
- Joined: Mon Dec 26, 2016 5:21 am
-
Contact:
Post
by pvn » Thu Jul 30, 2020 1:22 am
windows 10, wxwidgets-3.1.3, 64bit build
yes, grid demo shows the check box fine (checked, not checked on click)
-
pvn
- Experienced Solver

- Posts: 81
- Joined: Mon Dec 26, 2016 5:21 am
-
Contact:
Post
by pvn » Thu Jul 30, 2020 1:38 am
I was having
setting to true fixes it
related to this, I want to have the behavior of
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
-
ONEEYEMAN
- Part Of The Furniture

- Posts: 4824
- Joined: Sat Apr 16, 2005 7:22 am
- Location: USA, Ukraine
Post
by ONEEYEMAN » Thu Jul 30, 2020 1:40 am
Hi,
So, what do you do differently from the sample?
Thank you.
-
ONEEYEMAN
- Part Of The Furniture

- Posts: 4824
- Joined: Sat Apr 16, 2005 7:22 am
- Location: USA, Ukraine
Post
by ONEEYEMAN » Thu Jul 30, 2020 2:07 am
Hi,
pvn wrote: ↑Thu Jul 30, 2020 1:38 am
I was having
setting to true fixes it
related to this, I want to have the behavior of
1) also having text in the same cell
You can always create your own renderer.
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
Thank you.
-
pvn
- Experienced Solver

- Posts: 81
- Joined: Mon Dec 26, 2016 5:21 am
-
Contact:
Post
by pvn » Thu Jul 30, 2020 2:19 am
You can catch the appropriate event and then go thru all cells and check/uncheck the check box.
I do catch a click event for the column
Code: Select all
void PanelCurrent::OnCellLeftClick(wxGridEvent& ev)
{
if (ev.GetCol() == underlying(cols_t::ActionTaken))
{
but how to get access of the underlying control (the check box) so that I can explicitally make it checked ?
-
ONEEYEMAN
- Part Of The Furniture

- Posts: 4824
- Joined: Sat Apr 16, 2005 7:22 am
- Location: USA, Ukraine
Post
by ONEEYEMAN » Thu Jul 30, 2020 4:19 am
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?
Thank you.
-
pvn
- Experienced Solver

- Posts: 81
- Joined: Mon Dec 26, 2016 5:21 am
-
Contact:
Post
by pvn » Thu Jul 30, 2020 4:08 pm
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
-
Attachments
-

- Untitled.png (26.48 KiB) Viewed 588 times
-
doublemax
- Moderator

- Posts: 15655
- Joined: Fri Apr 21, 2006 8:03 pm
- Location: $FCE2
Post
by doublemax » Thu Jul 30, 2020 5:10 pm
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
Use the source, Luke!
-
pvn
- Experienced Solver

- Posts: 81
- Joined: Mon Dec 26, 2016 5:21 am
-
Contact:
Post
by pvn » Thu Jul 30, 2020 6:42 pm
ok, got it
Code: Select all
wxGrid* grid = new wxGrid(this, wxID_ANY);
grid->CreateGrid(10, 3);
grid->SetCellRenderer(3, 0, new wxGridCellBoolRenderer);
grid->SetCellEditor(3, 0, new wxGridCellBoolEditor);
grid->SetCellValue(3, 0, "1");
-
Nunki
- Filthy Rich wx Solver

- Posts: 225
- Joined: Fri Sep 14, 2012 8:26 am
- Location: Kontich, Belgium
-
Contact:
Post
by Nunki » Mon Aug 03, 2020 9:58 am
Hi pvn,
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.
Code: Select all
// 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();
}
with of course the entry
Code: Select all
EVT_GRID_CELL_LEFT_CLICK( tcGDoc::OnGridCheck )
in the event table.
with regards,
Nunki
-
PB
- Part Of The Furniture

- Posts: 2832
- Joined: Sun Jan 03, 2010 5:45 pm
Post
by PB » Mon Aug 03, 2020 10:45 am
BTW, I have noticed there have been recent changes in wxGridCellBoolEditor
https://github.com/wxWidgets/wxWidgets/ ... 86f902d7be
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).