tags:

views:

111

answers:

1

Hi all,

I'm trying to populate a wxListCtrl but after trying various methods can't seem to be able to populate it with items.

Basically, I want a list control that would have three columns with headings and will show values in rows. But I've tried InsertItem, SetItem, or InsertColumn methods but am only able to show the column headings but not the row data. Any help will be greatly appreciated! Thanks in advance!

A: 

You can add columns like this:

int column_width = 90;
my_list_ctrl->InsertColumn(0, L"ColumnText", wxLIST_FORMAT_LEFT, column_width);

You can add items like this:

int image_index = 0;
long list_index = my_list_ctrl->InsertItem(0, L"My Item text", image_index);

You can set the text of the subitems like this:

int column_index = 1;
my_list_ctrl->SetItem(list_index, column_index, L"Text");

You can setup an image list for your list like this:

my_list_ctrl->SetImageList(&img_list, wxIMAGE_LIST_SMALL);
Brian R. Bondy
Thanks! That worked!However, you've to insert a column first. This is how it looks like:<code>wxString col1(wxT("Column1")); // column headingwxString mystring(wxT("My value")); //column valuelong indx1 = alist->InsertColumn(0, col1); //you need indx1 var to insert item atlong itemIndex1 = alist->InsertItem(indx1, mystring, 0);</code>
azm882
@azm882: No problem, glad to help.
Brian R. Bondy
Thanks again Brian! I do have additional problem though...using the above methods I can show the value1 in column1 just fine ...however, I am not able to show value2 in colum2...I tried doing another InsertItem or SetItem but I'm only able to show values one row at a time...what I want to do is show something like "user id" in colum1 and "user name" in column2 (that will make up row 1) and then on next row show another user name + user id.Thanks again!
azm882
Hi Brian! Thanks again. Unfortunately I'm still not able to add second value to second column using your modified method.BTW, how do "accept" the answer? You've been very helpful and I appreciate your time and help!
azm882
I must add that I'm not long list_index = my_list_ctrl->InsertItem(0, L"My Item text", image_index); instead I've long list_index = my_list_ctrl->InsertItem(0, mywxString, image_index);
azm882
@azm882: That works for me as I pasted above, just make sure you have 2 columns added, and the column index is 0 based. I think you need to post the relevant code if it still doesn't work for you. Probably it is best to post it as a new question and put the link here so I will know to look at it. You can accept an answer by clicking on the checkmark next to the up/down arrows.
Brian R. Bondy
Brian thanks! here is the link to new question:http://stackoverflow.com/questions/2962057/how-to-add-value-to-second-column-using-wxlistctrl-in-wxwidgets-c-code
azm882