How to use OnGetItemColumnImage 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
TheGreatRambler
Knows some wx things
Knows some wx things
Posts: 29
Joined: Mon Feb 10, 2020 3:09 am

How to use OnGetItemColumnImage

Post by TheGreatRambler »

I am using a virtual wxListCtrl with a valid wxImageList set. I am inheriting from wxListCtrl and OnGetItemColumnImage is being called and I am returning the index of the image in the imagelist, but the image is never displayed. All the images are the same size (70 pixels). I also have OnGetItemText but I need images to be used in certain places and text to be used in other places. Also, if it is possible to not draw any image at certain times, that would be nice.
Last edited by TheGreatRambler on Mon Feb 10, 2020 8:56 pm, edited 1 time in total.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to use OnGetItemColumnImage

Post by doublemax »

That sounds correct. Please post the relevant code parts (creating the wxListCtrl and wxImageList and the OnGetItemColumnImage handler).

Also: Which wxWidgets version and platform are you using?
Use the source, Luke!
TheGreatRambler
Knows some wx things
Knows some wx things
Posts: 29
Joined: Mon Feb 10, 2020 3:09 am

Re: How to use OnGetItemColumnImage

Post by TheGreatRambler »

I was able to fix my problem, but I'm not sure exactly how I did it :wink:. I'll post the relevant examples for those that have problems with wxListCtrl and mixing text and images

Code: Select all

DataProcessing::DataProcessing(wxWindow* parent) : wxListCtrl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_VIRTUAL | wxLC_HRULES) {
	// ...
	// `imageList` is a member wxImageList of this custom class
	int imageIconWidth = 50;
	int imageIconHeight = 50;
	imageList.Create(imageIconWidth, imageIconHeight);
	// Do for each wxBitmap, remember the order the images were added
	imageList.Add(*(new wxBitmap()));
	// ... Repeat for each
	InsertColumn(0, "Header for text", wxLIST_FORMAT_CENTER, wxLIST_AUTOSIZE);
	// ... Repeat for each
	InsertColumn(1, "Header with image", wxLIST_FORMAT_CENTER, wxLIST_AUTOSIZE);
	// ...
	SetImageList(&imageList, wxIMAGE_LIST_SMALL);
}

int DataProcessing::OnGetItemColumnImage(long row, long column) const {
	if(column == 0) {
		// This is intended to be text
		return -1;
	} else {
		// Returns index in the imagelist
		res = 0;

		return res;
	}
}

wxString DataProcessing::OnGetItemText(long row, long column) const {
	if(column == 0) {
		// Returns some sort of text
		return "This is a row";
	} else {
		return "";
	}
}
As for the other stuff, make sure to use wxListCtrl::SetItemCount(int numberOfElements) whenever changing the number of elements. Everything should be automatic from there.
Post Reply