I have loaded combo as following.

cmdString = "select propertytypeid,typename from propertytype ";
             da = new SqlDataAdapter(cmdString, conString);            
             dt_PropertyType = new DataTable();
             da.Fill(dt_PropertyType);          

             cmb_PropertyType.DisplayMember = "Name";
             cmb_PropertyType.ValueMember = "ID";
             arr = new ArrayList();
             for (int i = 0; i < dt_PropertyType.Rows.Count; i++)
             {
                 arr.Add(new KeyValueData(dt_PropertyType.Rows[i][1].ToString(),int.Parse(dt_PropertyType.Rows[i][0].ToString())));             
             }             
             cmb_PropertyType.DataSource = arr;

but How Can I get the hidden id as I change selected item of the combo?

Recommended Answers

All 2 Replies

Try this one

int value = cmb.SelectedValue;

This will give you the selected value of the selected display member.

No need of loop.

da.Fill(dt_PropertyType);          
  cmb_PropertyType.DataSource = dt_PropertyType;
  cmb_PropertyType.DisplayMember = "typename";
  cmb_PropertyType.ValueMember = "propertytypeid";

and use SelectedValue property (see Post #2).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.