How do you set cell attributes of a virtual wxListCtrl ? 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
katuday
Earned some good credits
Earned some good credits
Posts: 134
Joined: Fri Aug 17, 2012 2:22 am

How do you set cell attributes of a virtual wxListCtrl ?

Post by katuday »

I have a virtual wxListCtrl

Code: Select all

class MyList : public wxListCtrl
….
virtual wxString OnGetItemText(long item, long column) const
{
// 
}

m_mylist = new MyList(this, ID_MYLIST, wxDefaultPosition, wxSize(-1, -1), wxLC_REPORT | wxLC_NO_HEADER | wxLC_VIRTUAL | wxLC_SINGLE_SEL | wxLC_HRULES | wxLC_VRULES );
How do I set the font, background color etc of the cell attributes?
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How do you set cell attributes of a virtual wxListCtrl ?

Post by doublemax »

There are a few more virtual methods you can override:
http://docs.wxwidgets.org/trunk/classwx ... ro-methods
Use the source, Luke!
katuday
Earned some good credits
Earned some good credits
Posts: 134
Joined: Fri Aug 17, 2012 2:22 am

Re: How do you set cell attributes of a virtual wxListCtrl ?

Post by katuday »

Thanks for the lead.
So I created an attributes object

Code: Select all

wxListItemAttr m_attr;
Set the attributes in the constructor of my model as

Code: Select all

m_attr.SetFont(wxFontInfo(12).FaceName("Tahoma"));
and implemented OnGetItemAttr as

Code: Select all

wxListItemAttr* OnGetItemAttr(long item) const
{
	return (wxListItemAttr *)&m_attr;
}
But this method is not being called at all. But my OnGetItemText is getting called as expected.
What did I miss?

I am on WIndows 10. Visual Studio 2017
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How do you set cell attributes of a virtual wxListCtrl ?

Post by doublemax »

It seems that under Windows OnGetItemAttr is not called, only OnGetItemColumnAttr.

I guess that's something that should be mentioned in the documentation.
Use the source, Luke!
katuday
Earned some good credits
Earned some good credits
Posts: 134
Joined: Fri Aug 17, 2012 2:22 am

Re: How do you set cell attributes of a virtual wxListCtrl ?

Post by katuday »

Super! Thanks again.
Post Reply