You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Download the Solution Example here: ComboBoxFromTable.dbsln


Solution Name: ComboBox from Table

Software Version: 10.1


Summary

This solution is an example on how to fill ComboBoxes through data table.


Technical Information

Initially, you need to gain control of the display's ComboBox. This is done with the following lines:


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.


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


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

// 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 value the client selected from the ComboBox and use it to update the other TextBoxes.


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:

  • No labels