Delete the contents of multiple cells in wxGrid. Topic is solved

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.
Post Reply
palikem
Experienced Solver
Experienced Solver
Posts: 69
Joined: Sat Oct 28, 2017 9:33 am
Location: Slovensko

Delete the contents of multiple cells in wxGrid.

Post by palikem » Thu Jan 25, 2018 10:17 am

Hi everybody.

I have a wxGrid table
I will mark all cells with a mouse
and I want to clear the contents of all the cells
using the Delete key
obr1.jpg
And it will do it to me
obr2.jpg
Deletes the contents of one cell
only the first number

Code: Select all

	Tabulka = new wxGrid(this, ID_TABULKA, wxPoint(569, 139), wxSize(162, 360));
	Tabulka->Show(false);
	Tabulka->SetFont(wxFont(23, wxSWISS, wxNORMAL, wxNORMAL, false, _("MS Sans Serif")));
	Tabulka->SetDefaultColSize(80);
	Tabulka->SetDefaultRowSize(40);
	Tabulka->SetRowLabelSize(1);
	Tabulka->SetColLabelSize(40);
	Tabulka->CreateGrid(8,2,wxGrid::wxGridSelectCells);
Windows 8
wxDev-C++ 7.4.2.569

User avatar
doublemax
Moderator
Moderator
Posts: 13990
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Delete the contents of multiple cells in wxGrid.

Post by doublemax » Thu Jan 25, 2018 10:50 am

Please show the code that you use to delete the cell contents.

The problem is most likely that you need several wxGrid methods to collect all selected cells:
GetSelectedCells
GetSelectedCols
GetSelectedRows
GetSelectionBlockTopLeft / GetSelectionBlockBottomRight
Use the source, Luke!

palikem
Experienced Solver
Experienced Solver
Posts: 69
Joined: Sat Oct 28, 2017 9:33 am
Location: Slovensko

Re: Delete the contents of multiple cells in wxGrid.

Post by palikem » Thu Jan 25, 2018 7:20 pm

I have no code for it
so it will not be so easy.

User avatar
doublemax
Moderator
Moderator
Posts: 13990
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Delete the contents of multiple cells in wxGrid.

Post by doublemax » Fri Jan 26, 2018 1:03 am

wxGrid does not do this on its own.

You'll have to add a write a key event handler and then delete the content of all selected cells yourself if the "delete" key was pressed.
Use the source, Luke!

palikem
Experienced Solver
Experienced Solver
Posts: 69
Joined: Sat Oct 28, 2017 9:33 am
Location: Slovensko

Re: Delete the contents of multiple cells in wxGrid.

Post by palikem » Fri Jan 26, 2018 1:55 pm

Simplicity is genius.

Code: Select all

void AdcFrm::AdcFrmKeyDown(wxKeyEvent& event)
{
    int x, y, z;
    
	x = event.GetKeyCode();
	
	if(x == WXK_DELETE || x == WXK_NUMPAD_DELETE){
        for(y=0; y<= 7; ++y){
            for(z=0; z<=1; ++z){
                if(Tabulka->IsInSelection(y, z)){
                    Tabulka->SetCellValue(y, z, _(""));
                }
            }
        }
    }
    event.Skip();
}

User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Delete the contents of multiple cells in wxGrid.

Post by eranon » Fri Jan 26, 2018 2:05 pm

Hello, Just a side note: you don't need _(""), unless you want to translate an empty string. Simple "" is enough.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3409
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Delete the contents of multiple cells in wxGrid.

Post by ONEEYEMAN » Fri Jan 26, 2018 6:45 pm

eranon,
Translating an empty string... That would be a very hard task. ;-)

Thank you.

User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Delete the contents of multiple cells in wxGrid.

Post by eranon » Fri Jan 26, 2018 9:08 pm

_(ʘ̅͜ʘ̅)
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]

Post Reply