I’m adding items to a ComboBox at runtime. Everything works fine but the problem is that the ValueMember is displaying only the value of the last record in all the items. And I want the current item in the ValueMember.
string qr1 = "select * from categorymaster";
SqlCommand cmd1 = new SqlCommand(qr1, con);
con.Open();
SqlDataReader dr1 = cmd1.ExecuteReader();
cmbcat.Items.Clear();
while (dr1.Read())
{
cmbcat.Items.Add(dr1[1].ToString());
cmbcat.DisplayMember = dr1[1].ToString();
cmbcat.ValueMember = dr1[0].ToString();
}
con.Close();
Can anyone help me out?
You do not need to use value member while looping