Bug #5145
closedNon linear comboBox
0%
Description
IS there a way to make combobox nonlinear in Wt or do i have to make my own combobox(select)? Currently calues are moving 0, 1, 2 ... I would like to repalce them whit some other values. I have a Db table with names, i want to make the values as the ID in database, and then i can use the ID-s from combobox to search DB for other stuff that are connected to the name.
Updated by Wim Dumon almost 9 years ago
- Status changed from New to Resolved
Hey,
I usually use WComboBox in combination with a model in order to have a direct link between the selected index and the object it represents. Combined with Dbo, you can use the Wt::Dbo::QueryModel to link the result of a Db query directly to a combobox. See WComboBox::setModel(), WComboBox::setModelColumn().
Wim.
Updated by Marko Taht almost 9 years ago
What about the empty selection? When using Standrt item model i can add empty selection but when takeing data from database how do i add empty selection? setData does not want to work, setCurrentIndex --1 does not what i want.
Updated by Wim Dumon almost 9 years ago
Did you call WComboBox:: setNoSelectionEnabled()?
Wim.
Updated by Marko Taht almost 9 years ago
I tryed still always defaults to first element. Nomatter where i put it or what i comment out, nothing changes.
Wt::WComboBox *authorCB = new Wt::WComboBox();
authorCB~~setModel(model~~>authorModel());
authorCB->setNoSelectionEnabled(true);
setFormWidget(AddAlbumFormModel::AutorField, authorCB,
[=]() {
std::string code = boost::any_caststd::string
(model->value(AddAlbumFormModel::AutorField));
int row = model->authorModelRow(code);
authorCB->setCurrentIndex(row);
},
[=]() {
std::string code = model~~authorCode(authorCB~~>currentIndex());
model->setValue(AddAlbumFormModel::AutorField, code);
});
Updated by Marko Taht almost 9 years ago
Ok i got it. I had to setNoSelwctionnabled before setting the model.
Updated by Roel Standaert about 8 years ago
- Status changed from Resolved to Closed