Event Handling in wxDataViewListCtrl Topic is solved

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
einneljeeva
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Jun 19, 2012 7:07 am

Event Handling in wxDataViewListCtrl

Post by einneljeeva » Mon Aug 27, 2012 6:22 am

Hi All,

I have created wxDataViewListCtrl with 10 rows and 10 columns. Now I want to set/change third column's item value depends upon the previous (second column) column's modified/changed value. (i.e) Whenever I change the second column's item value, the next column's item value also to be changed. I want to know which Event Handler should I use to achieve this?

Thanks in advance.

Regards,
Jeeva.V

User avatar
doublemax
Moderator
Moderator
Posts: 15079
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Event Handling in wxDataViewListCtrl

Post by doublemax » Mon Aug 27, 2012 9:51 am

You find the events in the base class wxDataViewCtrl:
http://docs.wxwidgets.org/trunk/classwx ... _ctrl.html
EVT_DATAVIEW_ITEM_VALUE_CHANGED seems to be the one you need.

Then you can change the value of the other column using wxDataViewListCtrl::SetValue
http://docs.wxwidgets.org/trunk/classwx ... 6a847bf83a
Use the source, Luke!

einneljeeva
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Jun 19, 2012 7:07 am

Re: Event Handling in wxDataViewListCtrl

Post by einneljeeva » Mon Aug 27, 2012 10:55 am

Hi Doublemax,

I am using the following statement.

Code: Select all

listctrl->SetTextValue( value, m_row_pos, m_column_pos + 1 );
Event that I processed: EVT_DATAVIEW_ITEM_VALUE_CHANGED

But I am unable to come out of the eventhandler after the above statement executed.

Thanks in advance

Jeeva.V

User avatar
doublemax
Moderator
Moderator
Posts: 15079
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Event Handling in wxDataViewListCtrl

Post by doublemax » Mon Aug 27, 2012 12:35 pm

Seems like the EVT_DATAVIEW_ITEM_VALUE_CHANGED gets called recursively. Other controls have a "ChangeValue" method for that, which changes the content, but doesn't generate an event. Apparently this was forgotten here.

The only quick solution i can think of: Read the value first, and if it's the same as the new value, don't call SetValue().
Use the source, Luke!

einneljeeva
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Jun 19, 2012 7:07 am

Re: Event Handling in wxDataViewListCtrl

Post by einneljeeva » Mon Aug 27, 2012 12:56 pm

Hi DoubleMax,

Yes , you are correct. I have attached the screenshot for your kind information.
Accroding to THICK Column modified value, the MINTHICK and MAXTHICK item value have to be changed.
Still i am facing the same problem.

Aniticipating reply.

Thanks in Advance.

Jeeva.V
Last edited by einneljeeva on Thu Aug 30, 2012 4:24 am, edited 1 time in total.

User avatar
doublemax
Moderator
Moderator
Posts: 15079
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Event Handling in wxDataViewListCtrl

Post by doublemax » Mon Aug 27, 2012 1:04 pm

You could try to catch EVT_DATAVIEW_ITEM_EDITING_DONE instead, If the value gets only edited manually by the user.
Use the source, Luke!

einneljeeva
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Jun 19, 2012 7:07 am

Re: Event Handling in wxDataViewListCtrl

Post by einneljeeva » Tue Aug 28, 2012 4:30 am

Hi Doublemax,

I tried EVT_DATAVIEW_ITEM_EDITING_DONE but I could not able to get manually edited-value. I got only previous value.

Thanks in Advance.

Jeeva.V

Nelson Joseph
Experienced Solver
Experienced Solver
Posts: 65
Joined: Sun Oct 26, 2008 5:15 am
Location: Chennai, India
Contact:

Re: Event Handling in wxDataViewListCtrl

Post by Nelson Joseph » Tue Aug 28, 2012 7:21 am

Hi Mr.Doublemax,

Whenever I call SetTextValue, EVT_DATAVIEW_ITEM_VALUE_CHANGED will be processed.
Is there any way to Stop event generated by SetTextValue?

Thanks
Regards,
Nelson Joseph

User avatar
doublemax
Moderator
Moderator
Posts: 15079
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Event Handling in wxDataViewListCtrl

Post by doublemax » Tue Aug 28, 2012 7:56 am

I tried EVT_DATAVIEW_ITEM_EDITING_DONE but I could not able to get manually edited-value. I got only previous value.
Yeah, i check the sources, the event is sent before the value is actually changed, because it can still be vetoed here.

So only idea i have left is to set a flag in your event handler yourself before you change the item. And if the flag is set you ignore the next event. Pretty ugly, but without changing the wxDataViewListCtrl sources, i don't see any other way.
Use the source, Luke!

User avatar
doublemax
Moderator
Moderator
Posts: 15079
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Event Handling in wxDataViewListCtrl

Post by doublemax » Tue Aug 28, 2012 7:58 am

Whenever I call SetTextValue, EVT_DATAVIEW_ITEM_VALUE_CHANGED will be processed.
Is there any way to Stop event generated by SetTextValue?
I don't think so. As i wrote before, other classes usually have a ChangeValue() method for that, but it was not implemented for this class.

You could try disconnecting the event handler before you change the value and reconnect afterwards.
Use the source, Luke!

Nelson Joseph
Experienced Solver
Experienced Solver
Posts: 65
Joined: Sun Oct 26, 2008 5:15 am
Location: Chennai, India
Contact:

Re: Event Handling in wxDataViewListCtrl

Post by Nelson Joseph » Wed Aug 29, 2012 1:09 pm

Jeeva:

This code will solve your problem.

First connect dynamically.

Code: Select all

m_dataViewListCtrl->Connect( wxID_DATAVIEW_CTRL, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEventHandler( MyFrame::OnItemValueChanged ), NULL, this );
Add the following to OnItemValueChanged

Code: Select all

m_dataViewListCtrl->Disconnect( wxID_DATAVIEW_CTRL, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEventHandler( MyFrame::OnItemValueChanged ), NULL, this );
Then set the value using SetTextValue()

Finally Add the following (Again you need to connect)

Code: Select all

event.Skip( true );
m_dataViewListCtrl->Connect( m_dataViewListCtrl->GetId(), wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEventHandler( MyFrame::OnItemValueChanged ), NULL, this );
Regards,
Nelson Joseph

einneljeeva
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Jun 19, 2012 7:07 am

Re: Event Handling in wxDataViewListCtrl

Post by einneljeeva » Thu Aug 30, 2012 4:25 am

@Doublemax: Thank You
Problem Solved

Post Reply