Associating data with wxListCtrl in virtual mode

Lloyd lloyd at cdactvm.in
Mon Dec 11 22:56:08 PST 2006


Thanks Andreas.

What I understood from your code is, when a mouse click event occurs it
gets the index of the currently selected item and it returns the data
from the Array (based on the index).

But my case is different! What I actually want is -

I have some column headers, and when the user clicks on the column
header I want to sort the list based on that column. In this case each
time the list is sorted, the index which returns will be changed for the
same data in the raw! (Because the raw position shuffles).

If it was not in wxLC_VIRTUAL mode I could have used
wxListCtrl::SetItemData() and wxListCtrl::GetItemData() 


Any suggestions?

Thanks,
  Lloyd



Lloyd wrote:
> Hi,
>  I am using the wxListCtrl in wxLC_REPORT|wxLC_VIRTUAL mode to insert
> the data. Is there any way for me to assign some kind of hidden data
> with each raw? (Which can be returned when mouse click event occur on
a
> raw)

You can define an objarr array,
then use it as usual in your click handler.
This is like I do in aUCBLogo's StackVars window:

//in the header:

wxArrayString namearr, valarr;
wxArrayPtrVoid objarr;

// in the implementation:

wxString StackVars::OnGetItemText(long item, long column) const
{
        if (inupdate)
                return wxEmptyString;
        if (!column)
                return namearr[item];
        return valarr[item];
}

void StackVars::OnClick(wxListEvent &ev)
{
        NodeP nd=NodeP(objarr[ev.GetIndex()]);
        if (!nd)
                return;
        nd->setExpanded(!nd->expanded());
        update();
}

Cheers,
Andreas



______________________________________
Scanned and protected by Email scanner




More information about the wx-users mailing list