Page 1 of 1

Changing wxGrid Grid Lines

Posted: Wed Nov 18, 2015 7:31 pm
by FlyingIsFun1217
Greetings,

Recently I've been getting back into C++, as well as wxWidgets. I'm currently trying to write a variation on the wxGrid component, in particular attempting to change the way it draws the divider lines through the cells. I noticed in the documentation that it was mentioned to override "GetRowGridLinePen" and return the pen desired to draw out the grid lines. Below is a sampling of what I'm attempting to do.

Code: Select all

MainApp::MainApp(const wxString &title) : wxFrame(NULL, wxID_ANY, title)
{
	GridComponent *gridCompOne = new GridComponent(this, wxID_ANY, wxDefaultPosition, wxSide(400, 400));
}

Code: Select all

GridComponent::GridComponent(wxWindow *parent, wxWindowID id, const wxPoint &gridPos, const wxSize &gridSize) : wxGrid(parent, wxID_ANY, gridPos, gridSize)
{
	wxGrid *gridInstance = new wxGrid(parent, wxID_ANY, gridPos, gridSize);
	gridInstance -> CreateGrid(numRows, 3, wxGridSelectCells);
}

wxPen GridComponent::GetRowGridLinePen()
{
	return wxPen(*wxBLACK, 1, wxPENSTYLE_SHORT_DASH);
}
I have to be missing something. Am I not overriding the GetRowGridLinePen function correctly? Am I going about creating a new component in the wrong way?

Thanks

Re: Changing wxGrid Grid Lines

Posted: Wed Nov 18, 2015 8:45 pm
by PB
I must be missing something: Why are you creating a wxGrid instance in the GridComponent ctor? Shouldn't the code be like

Code: Select all

GridComponent::GridComponent(wxWindow *parent, wxWindowID id, const wxPoint &gridPos, const wxSize &gridSize) : wxGrid(parent, wxID_ANY, gridPos, gridSize)
{ 
	CreateGrid(numRows, 3, wxGridSelectCells);
}
Also the signature for wxGrid::GetRowGridLinePen() is

Code: Select all

virtual wxPen 	GetRowGridLinePen (int row)
as it allows you to customize the pen for every row separately. I.e. your method which is missing the row parameter actually does not override anything. Perhaps you meant to override GetDefaultGridLinePen()?

Re: Changing wxGrid Grid Lines

Posted: Fri Nov 20, 2015 12:43 am
by FlyingIsFun1217
Indeed, I was looking at the class inheritance in the wrong way.

And yes, somehow I forget to add in the 'row' parameter to the overridden function.

Thanks!