If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Hi,
I am using wxDataViewListCtrl and event used is EVT_DATAVIEW_SELECTION_CHANGED.From this event,I would like to get column index for the selected row.
I have tried using the below code, where evt.GetColumn() returns me -1 and when I try to use evt.GetDataViewColumn()->GetModelColumn();, it crashes. I need to know if I am following the right steps to get the current column or is there anything else I need to be doing?
int row = lc->GetSelectedRow();
int col = evt.GetColumn();
wxDataViewColumn *col = lc->GetCurrentColumn();
int colno =lc->GetColumnPosition(col);
int col = evt.GetDataViewColumn()->GetModelColumn();
sivaranjani wrote: ↑Thu Mar 15, 2018 6:12 am
Hi,
I have tried using wxDataViewCtrl::HitTest,but column index always returning first index of the column.Is there any other solution?
Thanks
doublemax wrote: ↑Thu Mar 15, 2018 9:08 am
I tested with this code in the "dataview" sample and it worked:
The Real Problem is :
When drag the the horizon scroll bar in wxDataViewCtrl to the right side columns and some left column(s) invisible, HitTest will return wrong column.
How to solve?
recently I'm implementing a context_menu triggered by right click in the DataViewListCtrl and therefore I find this post. I have similar issue when getting the column of the selected item.
The context menu that pops up when I right click on an item has certain width, and the Hittest() could return a wrong column index (which is on the right of the selected item). I understand why this happens but is there a solution that in the context_menu I can still get the correct column of the selected item?
If yes, what are the exact circumstances under which this does not work?
When I right click on an item of the DataViewListCtrl and a context menu pops, and then I click a item of the menu, at this moment Hittest() (it works) returns the position of the mouse cursor, which could be eventually not where the item of the DataViewListCtrl covers, but the one on its right or below it, this makes me get the wrong column. What I need is still the selected item of the DataViewListCtrl when I act in the poped context menu.
You need to determine the item and column before you show the popup menu. Use wxWindow::GetPopupMenuSelectionFromUser() to show the popup. It's a blocking call, so when it returns, you still have the information about the selected item. https://docs.wxwidgets.org/trunk/classw ... 682a61a93e
doublemax wrote: ↑Fri Mar 22, 2024 9:14 am
You need to determine the item and column before you show the popup menu. Use wxWindow::GetPopupMenuSelectionFromUser() to show the popup. It's a blocking call, so when it returns, you still have the information about the selected item. https://docs.wxwidgets.org/trunk/classw ... 682a61a93e
Thank you for this tips. It now works and I get what is expected.