Page 1 of 1

wxListView with large icons and multiple columns

Posted: Sat Nov 15, 2008 2:40 pm
by Laurent22300
Hello,

I'm trying to get wxListView to display large (32x32) icons on multiple columns. I managed to get it to display one column but I don't know how to add more.

This is what I have so far:

Code: Select all

wxListView* listView = new wxListView(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_ICON);

wxImageList* imageList = new wxImageList(32, 32);

for (int i = 0; i < 4; i++) {
  wxIcon* icon = IconGetter::GetExecutableIcon(_T("c:\\windows\\system32\\shell32.dll"), 32, i);
  int imageIndex = imageList->Add(*icon);
  
  wxListItem* item = new wxListItem();
  item->SetText(_T("text"));
  item->SetImage(imageIndex);
  listView->InsertItem(*item);
}

listView->SetImageList(imageList, wxIMAGE_LIST_NORMAL);
So it works well except that it displays everything on only one column. I would expect it to shows the icons on one row then wrap when it reaches the end of line, and keep displaying the icons on the next row (like the "Tiles" view on Explorer). Is it possible to do that?

Thank you,

Laurent

Posted: Sat Nov 15, 2008 5:31 pm
by Laurent22300
So this is what I'm getting at the moment:

Image

and this is what I'd like to have:

Image

Any suggestions? Can it be done at all?

Posted: Sat Nov 15, 2008 6:21 pm
by doublemax
you probably have to use wxListCtrl directly and not wxListView. Check the "listctrl" sample.

Posted: Sat Nov 15, 2008 6:30 pm
by Laurent22300
Ok I've just figured out what was wrong. I was assigning the image list after having created the items; however it apparently has to be done before otherwise it just doesn't work properly.

So the right order is:

1. Create the image list
2. Assign it the list the view
3. Create the list items

This is how I've changed my code and now it's working:

Code: Select all

wxListView* listView = new wxListView(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_ICON);

wxImageList* imageList = new wxImageList(32, 32);

for (int i = 0; true; i++) {
  wxIcon* icon = IconGetter::GetExecutableIcon(_T("c:\\windows\\system32\\shell32.dll"), 32, i);
  if (!icon) break;
  imageList->Add(*icon);
}

listView->AssignImageList(imageList, wxIMAGE_LIST_NORMAL);

for (int i = 0; i < imageList->GetImageCount(); i++) {
  listView->InsertItem(i, _T("text"), i);
}