how to get default value of combo box to change to record value

acorn

Active member
Joined
Mar 8, 2008
Messages
32
Programming Experience
5-10
Hi there.

I have a data entry form that loads a bunch of reference data for several different combo boxes from XML files. Here's some sample code:

VB.NET:
           With Me.cmboSectionAQ1
                .DisplayMember = dsYNDNK.Tables(0).Columns(0).ColumnName
                .ValueMember = dsYNDNK.Tables(0).Columns(1).ColumnName
                .DataSource = dsYNDNK.Tables(0)
            End With

Once I've loaded my various combo boxes, I retrieve data from an oracle database. I'm wondering how i can get the values of each combo box to change to match the values that have been set in the currently active record?
Right now, the only logic i have to get the data is :
VB.NET:
Me.WTBTableAdapter.Fill(Me.BaselineDS.WTB)

And then I have a bunch of VCR controls that were created for me to navigate through all my records.
 
This should all be set up in the designer. Why exactly do you have two DataSets? All you data should be in one DataSet and then you can setup all the bindings in the designer.
 
Hi there.

I have a data entry form that loads a bunch of reference data for several different combo boxes from XML files. Here's some sample code:

VB.NET:
           With Me.cmboSectionAQ1
                .DisplayMember = dsYNDNK.Tables(0).Columns(0).ColumnName
                .ValueMember = dsYNDNK.Tables(0).Columns(1).ColumnName
                .DataSource = dsYNDNK.Tables(0)
            End With

Once I've loaded my various combo boxes, I retrieve data from an oracle database. I'm wondering how i can get the values of each combo box to change to match the values that have been set in the currently active record?
Right now, the only logic i have to get the data is :
VB.NET:
Me.WTBTableAdapter.Fill(Me.BaselineDS.WTB)

And then I have a bunch of VCR controls that were created for me to navigate through all my records.


As jmc indicates, in the designer, set the following:


If your combo is decoding values stored in another table e.g. main table stores 1, and this represents Mr, 2= Mrs, 3 = Miss etc:


cmboSectionAQ1 Properties Grid:
DataSource = BaseLineDS
DataMember = "WTB" 'the name of the table holding the decode values
DisplayMember = "SalutationText" 'Mrs, Mrs etc
ValueMember = "SalutationID" '1, 2 etc
(DataBindings)\SelectedValue = BaseLineDS.MainDataTable 'the main table holding the 1, 2, 3 to decode


If your combo is NOT decoding values stored in another table

cmboSectionAQ1 Properties Grid:
DataSource = BaseLineDS
DataMember = "WTB" 'the name of the table holding the list of values
DisplayMember = "SalutationText"
ValueMember = "SalutationText"
(DataBindings)\SelectedValue = BaseLineDS.MainDataTable
 
As jmc indicates, in the designer, set the following:


If your combo is decoding values stored in another table e.g. main table stores 1, and this represents Mr, 2= Mrs, 3 = Miss etc:


cmboSectionAQ1 Properties Grid:
DataSource = BaseLineDS
DataMember = "WTB" 'the name of the table holding the decode values
DisplayMember = "SalutationText" 'Mrs, Mrs etc
ValueMember = "SalutationID" '1, 2 etc
(DataBindings)\SelectedValue = BaseLineDS.MainDataTable 'the main table holding the 1, 2, 3 to decode


If your combo is NOT decoding values stored in another table

cmboSectionAQ1 Properties Grid:
DataSource = BaseLineDS
DataMember = "WTB" 'the name of the table holding the list of values
DisplayMember = "SalutationText"
ValueMember = "SalutationText"
(DataBindings)\SelectedValue = BaseLineDS.MainDataTable

Sorry if i'm being thick, but my datasource for the combo box is an XML file which I'm accessing on the fly.
So to recycle your example above, the database record might contain "1",
and the xml file will contain "Mr" and "1".
The display member is currently set to show "MR" and the value is set to save "1".
The reason why I have two separate boxes is because the client wants to see the numeric value associated with each option they select in the combo boxes. So the text boxes that show the numeric values are the bound items... and the combo boxes just populate these text boxes.
Hope that makes sense.

Thanks.
 
Read your XML file into the BaseLineDS.WTB data table and follow the first set of instructions
 

Latest posts

Back
Top