Position of an item in wxDataViewCtrl

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.
Post Reply
nandakishore
Experienced Solver
Experienced Solver
Posts: 57
Joined: Wed Feb 25, 2015 2:09 pm
Location: Chennai, India

Position of an item in wxDataViewCtrl

Post by nandakishore »

Hi,

How to get Current Item Position(row and column numbers) when a user click on particular cell in wxDataViewCtrl??

thanks,..
Got a Problem???..No worry..Focus on Solution not on Problem :P
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Position of an item in wxDataViewCtrl

Post by doublemax »

Either through methods of wxDataViewEvent ( GetItem() & GetColumn() )
http://docs.wxwidgets.org/trunk/classwx ... event.html

Or wxDataViewCtrl::HitTest()
http://docs.wxwidgets.org/trunk/classwx ... 6fff16eb0c
Use the source, Luke!
nandakishore
Experienced Solver
Experienced Solver
Posts: 57
Joined: Wed Feb 25, 2015 2:09 pm
Location: Chennai, India

Re: Position of an item in wxDataViewCtrl

Post by nandakishore »

I got Column number from GetColumn(), but how to get Row number after getting GetItem()??
Got a Problem???..No worry..Focus on Solution not on Problem :P
nandakishore
Experienced Solver
Experienced Solver
Posts: 57
Joined: Wed Feb 25, 2015 2:09 pm
Location: Chennai, India

Re: Position of an item in wxDataViewCtrl

Post by nandakishore »

nandakishore wrote:I got Column number from GetColumn(), but how to get Row number after getting GetItem()??
Got a Problem???..No worry..Focus on Solution not on Problem :P
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Position of an item in wxDataViewCtrl

Post by doublemax »

Isn't the item usually the one you need? Anyway, i haven't found a public method that returns the row for an item.
Use the source, Luke!
nandakishore
Experienced Solver
Experienced Solver
Posts: 57
Joined: Wed Feb 25, 2015 2:09 pm
Location: Chennai, India

Re: Position of an item in wxDataViewCtrl

Post by nandakishore »

Actually i want to display the status whenever user clicks on particular cell. so i need row and column numbers..
Got a Problem???..No worry..Focus on Solution not on Problem :P
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Position of an item in wxDataViewCtrl

Post by doublemax »

Are you using wxDataViewCtrl or wxDataViewListCtrl? In the latter case, there is wxDataViewListCtrl::ItemToRow()
http://docs.wxwidgets.org/trunk/classwx ... ad30be241f
Use the source, Luke!
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: Position of an item in wxDataViewCtrl

Post by iwbnwif »

I am relatively new to using wxDataViewCtrl and its descendants so I can't be sure that the following is totally correct.

I think the reason there is no "GetRow" option in the base wxDataViewCtrl is because the control is capable of displaying information in a tree format where "row" may not have a specific meaning.

If you want to display data in a table format which has rows of similarly presented data, I would suggest using wxDataViewIndexListModel and associating that model with your wxDataViewCtrl. You can then use mouse events generated by the control to get the corresponding row in the model.

For example:

Code: Select all

void SomeGUIClass::OnGridLeftDclick(wxDataViewEvent& event)
{
    unsigned int row = pMyIndexListModel->GetRow (event.GetItem());
    
    // ... whatever you want to do with the row
}
This is essentially the same as DoubleMax is saying, however I have suggested to use the basic wxDataViewCtrl and associate it with a model (rather than use the wxDataViewListCtrl directly) because:
  1. It gives you much greater flexibility over the display of the data in different columns (this is why I have become a fan of wxDataViewCtrls recently :wink:)
  2. One of the main wxWidgets devs told me that wxDataViewListCtrl is "broken" (https://groups.google.com/forum/?fromgr ... k8E677Yk6I). However I am not sure if this means the that the control is broken or the concept of a list model used by the control :?
By the way, I suggest wxDataViewIndexListModel instead of wxDataViewListModel because it allows you to do more things with 'row' based items once you have the row.
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
Post Reply