Good Day,
Please can anyone help me on how to display a value selected from a combobox when it has gotten data from the database; this is the code i have so far i get the data from the database into the combobox, but i am having challenges getting the selected value
from the combobox. the combobox gets the data from the database at the inititialization of the form.
help here will be great.
below is the code i have so far on getting the data but not on how to display the data
public Register()
{
InitializeComponent();
BindComboBox();
}
public void BindComboBox()//(ComboBox comboBoxName)
// private void Register_Load(object sender, EventArgs e)
{
string connectionString1 = "Data Source=Kels-PC;Initial Catalog=AGdb; User ID=sa; Password=esther;";
SqlConnection con = new SqlConnection(connectionString1);
SqlDataAdapter da = new SqlDataAdapter("Select CategoryName FROM Categorydb", con);
DataSet ds = new DataSet();
da.Fill(ds, "Categorydb");
cmbcategory.ItemsSource = ds.Tables[0].DefaultView;
cmbcategory.DisplayMemberPath = ds.Tables[0].Columns["CategoryName"].ToString();
// dothejob();
// comboBoxName.SelectedValuePath = ds.Tables[0].Columns["ZoneId"].ToString();
// getComboName(cmbsubcategory);
}
thank you