I'm pulling a list of customers from a MySQL(MariaDB) Database, and putting them into a combo box. this part works fine.
However I need the associated ID once someone goes through the list and selects from the list.
I'm using c# and Visual Studio 2019.
Here is my method:
private void load_Customer_ComboBox()
MySqlCommand sc = new MySqlCommand("SELECT CustomerName from bbb.Customers", con);
reader = sc.ExecuteReader();
DataTable dt = new DataTable();
comboBox1.ValueMember = "Id";
comboBox1.DisplayMember = "CustomerName";
comboBox1.DataSource = dt;
comboBox1.SelectedIndex = -1;
So when someone picks a value from the combo box, I need a way to get the Id that goes along with it. I've looked on the net and there are many conflicting ways to do it, but not alot of solutions.
I think I have to pull the value out of 'SelectedItemChanged' property of the ComboBox, but not sure how to do it.
Any help would be appreciated.