Hey George, 2009/4/7 George <[email protected]>: > I want to implement a combobox widget that display the full name of the item > and > returns as value the item code. Similar to this: > > example HTML: > > <SELECT NAME="marital_status"> > <OPTION SELECTED VALUE="">Select...</OPTION> > <OPTION VALUE="SNG">Single</OPTION> > <OPTION VALUE="MRD">Married</OPTION> > </SELECT> > > > I'm trying to use a class that derives from WAbstractListModel, and > reimplemented data() and rowCount() using WStringListModel as an example. I > used > the following to map the > > typedef std::pair< Wt::WString, Wt::WString > PairWString; > typedef std::map<int, PairWString > MapItemCode; > > Now I don't know how to declare the signal "activated" to retrieve the > selected > value? Or am I taking the wrong approach altogether?
The 'activated' signal and the current index are properties of the view, not the model. WComboBox::activated and Ext::ComboBox::activated provide an integer index that indicates the row of the selected item, which is the same as the currentIndex() value. In your case, I would suggest you define the following behavior for your model: - have it return the display WString as DisplayRole - have it return the value WString (or rather std::string?) as UserRole Then, starting from the selected row, you can get to the value using: boost::any_cast<std::string>(combo->model()->data(row, 0, Wt::UserRole)); I don't think you need a map in your model implementation. You can simply use a vector of display/value pairs. Regards, koen ------------------------------------------------------------------------------ This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com _______________________________________________ witty-interest mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/witty-interest
