tags:

views:

149

answers:

2

I've following code:

int column_width = 100;

long indx1 = alist->InsertColumn(0, L"User Name", wxLIST_FORMAT_LEFT, column_width);

long indx2 = alist->InsertColumn(1, L"User Id", wxLIST_FORMAT_LEFT, column_width);

long itemIndex1 = alist->InsertItem(indx1, L"John Smith", -1);

alist->SetItem(indx1, 1, L"jsmith");

I expect to see two columns with User Name and User Id as heading with "John Smith" and "jsmith" as values on the first row. Instead I only see "John Smith" under column User Name but nothing under User ID column. Here is a link to the snapshot showing the result: http://drop.io/agtyt6s

Thanks!

A: 

Here is a minimal sample that displays two columns. Note that I am using the index item returned by the InsertItem method in the SetItem method.

#include <wx/wx.h>

class Frame : public wxFrame
{
public:
  Frame():
    wxFrame(NULL, wxNewId(), _("App"))
  {
    wxBoxSizer * box = new wxBoxSizer(wxVERTICAL);

    wxListCtrl * listCtrl = new wxListCtrl(this, wxNewId(), wxDefaultPosition, wxDefaultSize, wxLC_REPORT);
    listCtrl->InsertColumn(0, _("User Name"));
    listCtrl->InsertColumn(1, _("User ID"));

    long index = listCtrl->InsertItem(0, _("John Smith"));
    listCtrl->SetItem(index, 1, _("jsmith"));

    box->Add(listCtrl, 1, wxEXPAND, 0);
    SetSizer(box);
    box->SetSizeHints(this);
    Show(true);
  }
};

class App : public wxApp
{
  bool OnInit()
  {
    SetTopWindow(new Frame());
  }
};

IMPLEMENT_APP(App);
small_duck
I tried all combinations but it still does not show the second column value...
azm882
small_duck,Thanks for your code. I was doing the same thing without any success. I even copy and pasted your code to try it out but I still can't seem to show the second column value!
azm882
Weird. See if you can try it on another platform or with another compiler, because it starts looking like it could be your problem!
small_duck
A: 

Ok, I finally got it resolved by the help of wxWidgets forum contributors. Here is what the issue was: I was using

alist1 = new wxListCtrl( m_panel1, wxID_ANY, wxDefaultPosition, wxSize( 300,-1 ), wxLC_ICON|wxLC_REPORT|wxLC_SINGLE_SEL );

as the style of the wxListCtrl. It turns out that wxLC_ICON and wxLC_REPORT are mutually exclusive so you can only have one. When I removed wxLC_ICON it worked just fine! Thanks again for your help small_duck!

azm882