wxListView with large icons and multiple columns 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
Laurent22300
Knows some wx things
Knows some wx things
Posts: 30
Joined: Sun Sep 07, 2008 9:38 am
Contact:

wxListView with large icons and multiple columns

Post by Laurent22300 » Sat Nov 15, 2008 2:40 pm

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

Laurent22300
Knows some wx things
Knows some wx things
Posts: 30
Joined: Sun Sep 07, 2008 9:38 am
Contact:

Post by Laurent22300 » Sat Nov 15, 2008 5:31 pm

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?

User avatar
doublemax
Moderator
Moderator
Posts: 15283
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax » Sat Nov 15, 2008 6:21 pm

you probably have to use wxListCtrl directly and not wxListView. Check the "listctrl" sample.
Use the source, Luke!

Laurent22300
Knows some wx things
Knows some wx things
Posts: 30
Joined: Sun Sep 07, 2008 9:38 am
Contact:

Post by Laurent22300 » Sat Nov 15, 2008 6:30 pm

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);
}

Post Reply