Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 435
  • Last Modified:

Bound combobox - how to set initial entry and how to detect change

Hi Experts,

I have a bound combobox.
The table that it is bound to has two relevant fields, both strings: ID and Title.

The combobox displays Title.

When my form starts up I want the combobox to display the Title that corresponds to ID=IDrequired.

When the user makes a selection from the combobox, I want to get the value of ID (let's call it IDselected).

Regards,
Leigh
0
LeighWardle
Asked:
LeighWardle
  • 2
1 Solution
 
CrashmanCommented:
I really dont understand at all, but

--select value
cmbinfo.selectedvalue

and for capture change. in the combo events, selectedindexchange

http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.selectedindexchanged.aspx

and for assign:
cmbinfo.selectedvalue = 2
0
 
LeighWardleAuthor Commented:
Here are some records from the bound table:

ID                                 Title
Asphalt                                  Asphalt
Cemented                          Cement Stabilised
CementedPC                          Cement Stabilised (post-cracking)
Subgrade04                          Subgrade (Austroads 2004)

The combobox displays Title.

When my form starts up I want the combobox to display the Title that corresponds to ID=IDrequired.  For example, if IDrequired="Subgrade04" I want the combo to display "Subgrade (Austroads 2004)"

When the user makes a selection from the combobox, I want to get the value of ID (let's call it IDselected). For example, if the user selects "Subgrade (Austroads 2004)" I want  IDselected to equal "Subgrade04".
0
 
CodeCruiserCommented:
Assuming that you correctly set the DisplayMember and ValueMember properties of the combobox when binding, you can simply do following to select a particular item

cbx.SelectedValue = IDRequired

And when you want to get the selection, you simply reverse the above

IDSelected = cbx.SelectedValue
0
 
LeighWardleAuthor Commented:
Just for the record, I put this statement inside cbx_SelectedIndexChanged:

IDSelected = cbx.SelectedValue
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now