Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Download the Solution Example here: ComboBoxFromTable.dbsln


Solution Name: ComboBox from Table

Software Version: 10.1


Summary

This solution is an example on demonstrates how to fill populate ComboBoxes through using a data table.

Image Added


Technical Information

InitiallyFirst, you need to gain obtain control of the ComboBox on the display's ComboBox. This is done with achieved through the following lines:


Code Block
ComboBox cbxListCodes;

public void DisplayOpening()
{
    cbxListCodes = CurrentDisplay.GetControl("cbxListCodes") as ComboBox;
}


After that, you need to load your data table. In this example, we will retrieve the entire table asynchronously.


Code Block
// Selects the whole table
@Dataset.Table.Products.WhereCondition = "";
DataTable dt = await @Dataset.Table.Products.SelectCommandAsync();


Next, using you can use a simple foreach loop , you can select the desired rows and add them to select which rows to add to the ComboBox, as demonstrated shown in the code snippet below.

Code Block
// Inserts each row to the combobox
foreach (DataRow row in dt.Rows)
{
    cbxListCodes.Items.Add(row["ListCode"]);
}


Finally, by using an EventHandler, you can determine which the value selected by the client selected from the ComboBox and use it to update the other TextBoxes accordingly.


Code Block
cbxListCodes.SelectionChanged += new SelectionChangedEventHandler(codeChanged);

public void codeChanged(object sender, SelectionChangedEventArgs args)
{
if(cbxListCodes.SelectedValue == null)
return;

    //Selecting from the DB only the Item corresponding to the Code Selected in the ComboBox
@Dataset.Table.Products.WhereCondition = "ListCode = " + cbxListCodes.SelectedValue.ToString();
@Dataset.Table.Products.SelectCommandAsync();
}



Reference Information

→ See "Displays and Visualization” for more information.


In this section:

Page Tree
rootSolution Examples
spacesV10