How to read data from wxListCtrl

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
VonGodric
Earned some good credits
Earned some good credits
Posts: 103
Joined: Sun Jan 30, 2005 9:31 pm
Contact:

How to read data from wxListCtrl

Post by VonGodric »

I have a small problem, I have wxListCtrl with 4 columns. And I created it like this:

Code: Select all

    FBConsole = new wxListCtrl(FBCodePanel, 
                               wxID_ANY, 
                               wxDefaultPosition, 
                               wxDefaultSize, 
                               wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_HRULES|wxLC_VRULES );

    wxListItem itemCol;
    itemCol.SetText(_T("Line"));
    itemCol.SetAlign(wxLIST_FORMAT_LEFT);
    FBConsole->InsertColumn(0, itemCol);

    itemCol.SetText(_T("File"));
    itemCol.SetAlign(wxLIST_FORMAT_LEFT);
    FBConsole->InsertColumn(1, itemCol);
    
    itemCol.SetText(_T("Error nr"));
    itemCol.SetAlign(wxLIST_FORMAT_LEFT);
    FBConsole->InsertColumn(2, itemCol);

    itemCol.SetText(_T("Message"));
    itemCol.SetAlign(wxLIST_FORMAT_LEFT);
    FBConsole->InsertColumn(3, itemCol);
    
    
    FBConsole->SetColumnWidth( 0, 60 );
    FBConsole->SetColumnWidth( 1, 150 );
    FBConsole->SetColumnWidth( 2, 60 );
    FBConsole->SetColumnWidth( 3, 600 );
and I want to read data from it I previously have set into it with:

Code: Select all

 void MyFrame::AddListItem ( int Linenr, int ErrorNr, wxString FileName, wxString Message ) {

    // FBConsole is a pointer to wxListCtrl control
    
    Message=Message.Trim(true).Trim(false);
    wxString lnr;
    if (Linenr!=-1)
        lnr << Linenr;
    int Itemcount = FBConsole->GetItemCount();
    long tmp = FBConsole->InsertItem(Itemcount, lnr, 0);
    FBConsole->SetItemData(tmp, 0);
    FBConsole->SetItem(Itemcount, 1, FileName);
    lnr = "";
    if (ErrorNr!=-1)
        lnr << ErrorNr;
    FBConsole->SetItem(Itemcount, 2, lnr);
    FBConsole->SetItem(Itemcount, 3, Message);
}
I can read only first column where is "line number", but how to read rest of the "boxes" on the same line that are under different columns. Like Filename for example?

Just to clearify here's the screenshot of it all: (green box is okay. I can read it, but red one is what I want to read)
Image
vdell
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 536
Joined: Fri Jan 07, 2005 3:44 pm
Location: Finland
Contact:

Post by vdell »

I have wrapped this operation for my base List control class like this:

Code: Select all

const wxString OListCtrl::GetColText ( long item, long col ) const
{
	wxListItem list_item;
	list_item.SetId ( item );
	list_item.SetColumn ( col );
	list_item.SetMask ( wxLIST_MASK_TEXT );
	GetItem ( list_item );
	return list_item.GetText();
}
HTH
Visual C++ 9.0 / Windows XP Pro SP3 / wxWidgets 2.9.0 (SVN) | Colligere
VonGodric
Earned some good credits
Earned some good credits
Posts: 103
Joined: Sun Jan 30, 2005 9:31 pm
Contact:

Post by VonGodric »

Thank you, that works :P
Post Reply