How to handle multiple dataview selections?
How to handle multiple dataview selections?
I have a wxMenu for handling certain actions on a single wxDataViewListCtrl row. I want to be able to select multiple rows, and perform the action that is being clicked on the wxMenu for all the selected rows, but I can't seem to find a method to get index for all the selected rows, for example if there are 20 items in the dataview, and 4,8,15 and 17 are selected I want to be able to get these indexes, so can I call a for loop for these indexes or something with GetSelectedItemsCount() as a condition perhaps.
Re: How to handle multiple dataview selections?
Look in the base class, there is wxDataViewCtrl::GetSelections
https://docs.wxwidgets.org/trunk/classw ... b254c41c86
https://docs.wxwidgets.org/trunk/classw ... b254c41c86
Use the source, Luke!
Re: How to handle multiple dataview selections?
I see, but what is wxDataViewItemArray here? Do I have to make that array myself? If so what will be its value? Because just doing, ( I selected 0, 2 and 4th row)doublemax wrote: ↑Wed Apr 07, 2021 10:07 am Look in the base class, there is wxDataViewCtrl::GetSelections
https://docs.wxwidgets.org/trunk/classw ... b254c41c86
Code: Select all
wxDataViewItemArray row_array;
int row = m_DVLC->GetSelections(row_array);
wxLogDebug("Value of row: %d", row);
Code: Select all
16:19:56: Debug: Value of row: 3
16:19:56: Debug: Value of row: 3
16:19:56: Debug: Value of row: 3
Re: How to handle multiple dataview selections?
From the "dataview" sample, code to delete all seletected items:
Code: Select all
void MyFrame::DeleteSelectedItems()
{
wxDataViewItemArray items;
int len = m_ctrl[Page_Music]->GetSelections( items );
for( int i = 0; i < len; i ++ )
if (items[i].IsOk())
m_music_model->Delete( items[i] );
}
Use the source, Luke!
Re: How to handle multiple dataview selections?
I see, I'm try to change toggle column value based on the selected rows, and items cannot be used in GetToggleValue(), how would I get the individual rows, as doing this gives error,doublemax wrote: ↑Wed Apr 07, 2021 11:23 am From the "dataview" sample, code to delete all seletected items:Code: Select all
void MyFrame::DeleteSelectedItems() { wxDataViewItemArray items; int len = m_ctrl[Page_Music]->GetSelections( items ); for( int i = 0; i < len; i ++ ) if (items[i].IsOk()) m_music_model->Delete( items[i] ); }
Code: Select all
wxDataViewItemArray items;
int rows = m_SampleListView->GetSelections(items);
for (int i = 0; i < rows; i++)
{
if (m_SampleListView->GetToggleValue(items[i], 0))
m_SampleListView->SetToggleValue(false, items[i], 0);
else
m_SampleListView->SetToggleValue(true, items[i], 0);
}
Re: How to handle multiple dataview selections?
wxDataViewListCtrl::ItemToRow
https://docs.wxwidgets.org/trunk/classw ... ad30be241f
wxDataViewListCtrl::RowToItem
https://docs.wxwidgets.org/trunk/classw ... ff6b2f7fd5
https://docs.wxwidgets.org/trunk/classw ... ad30be241f
wxDataViewListCtrl::RowToItem
https://docs.wxwidgets.org/trunk/classw ... ff6b2f7fd5
Use the source, Luke!