mac wrote:Hi,
I just converted my listbox deleting code to use a listctrl instead and as this is my first time doing this and i just wrote this myself i'm sure it's not as good as somebody else's code out there so i'd like to compare your better solution please
If you could post code thanks!
here is what i got working now to delete selected items in a wxListCtrl
Code: Select all
void MyFrame::OnBitmapbuttonMinusClick( wxCommandEvent& event )
{
// if no files do nothing
if (filez->GetItemCount() == 0)
{
//wxMessageBox(_T("none"),_T("none"));
return;
}
// if 1 file delete it even if not selected!
if (filez->GetItemCount() == 1)
{
//wxMessageBox(_T("one"),_T("one"));
filez->DeleteItem(0);
return;
}
// listctrl delete all selected...doing REVERSE again
int total_items = filez->GetItemCount();
int i = 0;
while (total_items > i)
{
if (filez->GetItemState((total_items - 1) - i, wxLIST_STATE_SELECTED) == wxLIST_STATE_SELECTED)
{
filez->DeleteItem((total_items - 1) - i);
}
i++;
}
}
filez is now a wxListCtrl*
I wanted the same functionality as this post
http://forums.wxwidgets.org/viewtopic.php?t=13955 but now I'm using a listctrl instead of a listbox.
Thanks.
Well when I posted this I only wrote it and tested it on XP now I've just checked it and I had to include the imaglist.h for my slackware for it to work...but it DOES NOT work on OS X ppc 10.4.9 =/
??
edit: fixed it :p
I replaced my while loop with basically the sample in the wx help on wxListCtrl::GetNextItem and it works in mac os x now too
Code: Select all
long item = -1;
for (;;)
{
item = filez->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (item == -1)
break;
filez->DeleteItem(item);
}
edit 2:
=/
theres a bug in the wx sample code sometimes it leaves a selected item and doesnt delete it...?!
I shouldn't have accepted this yet. *sigh*
edit 3 =)
I'm done with this screw it...
Code: Select all
void MyFrame::OnBitmapbuttonMinusClick( wxCommandEvent& event )
{
// if no files do nothing
if (filez->GetItemCount() == 0)
{
//wxMessageBox(_T("none"),_T("none"));
return;
}
// if 1 file delete it even if not selected!
if (filez->GetItemCount() == 1)
{
//wxMessageBox(_T("one"),_T("one"));
filez->DeleteItem(0);
return;
}
// listctrl delete all selected ----------------
#ifdef __WXMAC__
// ugly mac fix o.o'
long item = -1;
for(;;)
{
item = filez->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (item == -1)
break;
filez->DeleteItem(item);
}
item = -1;
for(;;)
{
item = filez->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (item == -1)
break;
filez->DeleteItem(item);
}
#else
int total_items = filez->GetItemCount();
int i = 0;
while (total_items > i)
{
if (filez->GetItemState((total_items - 1) - i, wxLIST_STATE_SELECTED) == wxLIST_STATE_SELECTED)
{
filez->DeleteItem((total_items - 1) - i);
}
i++;
}
#endif
// -----------------------------------------
}
This works in linux, msw, and mac ... I know its ugly to repeat code and use #ifdef but the mac one when selecting multiple files to remove would sometimes keep one so this above code works and fixes that I spent too much time on this already :/