Powerbuilder get selected value from a dropdown list - list

How can I get the value I've selected in a dropdown list?
I've tried something like this but it won't work, ls_est_an is null:
ll_row = dw_est_an.rowcount()
dw_est_an.GetChild( "est_an" , dddw )
ls_est_an = dw_est_an.object.est_an[ll_row]

You can use the GetSelectedRow method on the datawindow child.
In your example you are getting the value of 'est_an' for the last row in the datawindow 'dw_est_an'.
To get the value of the selected row in the dropdown datawindow you can use
something like:
long ll_dddwrow
string ls_val
ll_dddwrow = dddw.getselectedrow(0)
IF ll_dddwrow > 0 THEN
ls_val = dddw.getitemstring(ll_dddwrow, 'columnname')
END IF
This assumes whatever column in the dropdowndatawindow object is of type string.

Related

error in passing arguments and list duplicating passed items two times in flutter

I am using arguments method in Navigator to pass a List
Navigator.pushNamed(context, '/cam', arguments: {'label' : list});
list is a string of items separated by comma for eg: item1, item2
and on receiving the the map of data from the first screen in second screen, I store that in a List by
data = ModalRoute.of(context).settings.arguments;
print(data);
rekognition.add(data['label']);
print(rekognition);
under Widget build and the above print statements prints [null, item1, item2] and [null, item1, item2, null, item1, item2] respectively.
this is where the problem is I don't why null pop up here and the list adds all the items second time
also
for (x=0; x<ing.length; x++) {
list = '$list , ${ing[x]}';
}
ing is again a list and its equal to List<dynamic>();
all I wanted to do was send a list of items which is added in the first screen and or else a empty list to the second screen and add all those received data to another variable in second screen and do object detection and add the label to the list of items that was passed form the first screen and go back to the first screen again with data of the all the list items including the data that was passed and added
I was able to solve null error by sending the list ing as a single variable instead of a map by
arguments: ing.toList() and the reason why the list in second screen adding items second time because of setState() function which on calling will rebuild the full widget tree hence my function of adding the items to list is called again, this was solved by a if condition
if (mylist.length == 0 ) { mylist.add(data); }

Accessing a Combobox inside a dataGridView Column?

I'm working on a scheduling program, and inside the dataGridView, we have a few ComboBox Columns that are populated by 3 entries upon creation, but I wanted to be able to add more as the user creates them, but I have no idea how you would access the combobox data. Any help is appreciated!
// this is initialized in a separate part.
/* System::Windows::Forms::DataGridView^ dataGridView;*/
System::Windows::Forms::DataGridViewComboBoxColumn^ newCol =
(gcnew System::Windows::Forms::DataGridViewComboBoxColumn());
dataGridView->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewComboBoxColumn^ >(1) {newCol});
// add the choices to the boxes.
newCol->Items->AddRange("User inputted stuff", "More stuff", "Add New...");
Solution
If you have access to the data from the user entry and you know the column index for the DataGridViewComboBoxColumn, you should be able to just do the following wherever needed:
DataGridViewComboBoxColumn^ comboboxColumn = dataGridView->Columns[the_combobox_column_index];
if (comboboxColumn != nullptr)
{
comboboxColumn->Items->Add("the new user entry");
}
Comments Response
how could you change the selected index of that combobox (the one that
the edit was triggered on)? [...] we want it so that when the new item
is added the selected index is set to that new item).
Couple of ways come to mind.
Add a single line within the if-statement of the above code. This will set the default displayed value for each DataGridViewComboBoxCell in the DataGridViewComboBoxColumn.
if (comboboxColumn != nullptr)
{
comboboxColumn->Items->Add("the new user entry");
comboboxColumn->DefaultCellStyle->NullValue = "the new user entry";
}
Pros: Clean, efficient. Previous user-selected values are left intact. The cell's FormattedValue will display the new user value by default if no other selection has been made.
Cons: Doesn't actually set a cell's selected value, so Value will return null on cells not explicitly user-selected.
Actually set the value of certain cells (based on your criteria) to the user-added value.
if (comboboxColumn != nullptr)
{
comboboxColumn->Items->Add("the new user entry");
for (int i = 0; i < dataGridView->Rows->Count; i++)
{
DataGridViewComboBoxCell^ cell = dataGridView->Rows[i]->Cells[the_combobox_column_index];
if ( cell != nullptr /* and your conditions are met */ )
{
cell->Value = "the new user entry";
}
}
}
Pros: The Value of targeted cells is actually set to the new user value.
Cons: Logic deciding which cells should be affected is more complicated.

C++ CListCtrl - GetItemData() returning wrong value?

I have a C++ application with an SQL backend, and have been storing the row id of any retrieved columns (an integer, primary key bigint in the database) with SetItemData() on list control rows as required. This is then retrieved with GetItemData() if that ID needs to be queried.
I am now getting a weird problem in that, in this one scenario, GetItemData() is returning a random 7-digit number instead of the stored ID. When I add the row I use the following code:
CListCtrl& lc = GetListCtrl();
for (int i = 0; i < vInsertItems.size(); i++) {
int j = lc.InsertItem(i,i.strName);
DWORD dwdRowID = (DWORD)cammms,nRowID;
lc.SetItemData(j,dwdRowID);
}
To retrieve and check the value I can do the following (where I have determined that nCurrentlySelectedIndex is correct):
CListCtrl& lc = GetListCtrl();
int msgID = lc.GetItemData(nCurrentlySelectedIndex);
CString debugInt; debugInt.Format(_T("debugInt = %d"),msgID);
AfxMessageBox(debugInt);
What is bizarre, is that if I run the second batch of code directly after the first, it is all fine. But if I run it in a separate function, msgID becomes set to a set of random 7 digits, different every time.
Does anyone have any idea what could be causing this?

QComboBox::findData() always returns -1

I am trying to get the id of the record in the model from a QCombobox with findData(index), but when select a item, it retunrs -1. It has been working in another project, but this is the second one that doesn't work. Here's my code:
modAnfi = new QSqlTableModel(this);
modAnfi->setQuery("SELECT id, (nombres || ' ' || apellidos) as Nombre, nombres, apellidos FROM tbPersonas WHERE activo=1");
comboAnfitrion->setModel(modAnfi);
comboAnfitrion->setModelColumn(1);
comboAnfitrion->setEditable(true);
comboAnfitrion->completer()->setCompletionMode(QCompleter::PopupCompletion);
connect(comboAnfitrion, SIGNAL(currentIndexChanged(int)), this, SLOT(currentIndexChangeAnfitrion(int)));
and:
void controlReg::currentIndexChangeAnfitrion(int index)
{
qDebug() << comboAnfitrion->findData(index); // -1
qDebug()<< comboAnfitrion->itemData(1); // QVariant(Invalid)
}
Thanks for your time, any help will be appreciated.
You have to use the model you assign to the comboBox, use the index to look for it:
modAnfi->data(modAnfi->index( index, 0));
Check the QComboBox documentation; from the findData description, quoting:
Returns the index of the item containing the given data
Where you are passing index as the "given data". However, index is already an index in the combobox. But you're obviously not looking for an index (since you already have one).
I suspect you actually want to call the itemData method instead? That would retrieve the data associated with an element for a given index.

QCombobox doesn't select when changing currentIndex

In my constructor I connect to a Sqlite Database and read "Categories" (QStrings) from it.
I store them in a QList. I checked via debugger if they're empty, but everything is fine.
The int currCategoryIndex is set to 0 in my initializer list. And since QComboboxes start indexing from 0 it should be the first item.
An extract from my constructor:
dm.readDB_C(c_list); //reads into c_list
if(c_list.count() > 0) //has 1 or more items
updateCategories();
This is the part where I read the database, check if it's empty and if not call a function which adds those categories to a QComboBox.
updateCategories() function :
void MainWindow::updateCategories()
{
for(int i = 0; i < c_list.count(); i++){
if(ui->cmbCategory->findText(c_list[i]) != -1){ //-1 means "not found"
continue;
} else {
ui->cmbCategory->addItem(c_list[i]); //Add to QCombobox
}
}
ui->cmbCategory->setCurrentIndex(currCategoryIndex); //Should be the first item
}
I have all items in my QCombobox but none is selected. I have to click the box and select one myself. That's not supposed to happen.
What is wrong? Why doesn't it select one itself?
Edit:
currentIndexChanged signal:
void MainWindow::on_cmbCategory_currentIndexChanged(int index){
currCategoryIndex = index;
}
Perhaps the first item is empty?
Since you only add items to QComboBox, it is possible that index 0 is (from the beginning) an empty string.
try putting
ui->cmbCategory->removeItem(0);
in the beginning of updateCategories to check if it is the case
also, if currCategoryIndex is an index that does not exist (for example -1) QComboBox will also be empty (even if there is no empty string to choose) - in this case you can try to hardcode 0 in the function (if you want the item to always be the first one), or add additional check, for example:
if (0 > currentCategoryIndex || currentCategoryIndex > ui->cmbCategory->count())
currentCategoryIndex = 0