• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

Binding Sources Navigation

I have a binding source for an Address combobox in a project

The binding source has three columns suburbid, suburbname, postcodeid.  suburbid = value, suburbname = displaytext

I need to extract the postcodeid when a user selects a suburb. How do I do this.

Phill
0
PhillO
Asked:
PhillO
  • 3
  • 3
1 Solution
 
vbturboCommented:
HI

     
        ComboBox1.ValueMember = "postcodeid"
        ComboBox1.DisplayMember = "suburbname"
        ComboBox1.DataSource = ds.Tables("Address")

Or

      With Me.ComboBox1
            .ValueMember = "postcodeid"
            .DisplayMember = "suburbname"
            .DataSource = ds.Tables("Address")
            .DataBindings.Add("SelectedValue", ds.Tables("Address"), "postcodeid")
        End With


    Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged

        Dim i As Integer = ComboBox1.SelectedValue

         MessageBox.Show(ComboBox1.SelectedValue)

         'Or you could get the specific row from the table you bound to the cbo
        If ComboBox1.SelectedIndex <> -1 Then
            Dim dr As DataRow = ds.Tables("Address").Rows(ComboBox1.SelectedIndex)
            MessageBox.Show(dr.ToString())
    End Sub

Hope this helps

vbturbo
0
 
PhillOAuthor Commented:
Thanks for the reply

But how do I retrieve the actual postcodeid from the selected row
0
 
vbturboCommented:
this you do in the ComboBox1_SelectedValueChanged event

    Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged

        Dim i As Integer = ComboBox1.SelectedValue

         MessageBox.Show(ComboBox1.SelectedValue)


the value(ComboBox1.SelectedValue) is the id value that you specified "ComboBox1.ValueMember = "postcodeid"!

That is the actual postcodeid from the selected  "suburbname"

suburbname          ID

Jane                       7    
Hans                      19                   MessageBox.Show(ComboBox1.SelectedValue) is = 19    
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
PhillOAuthor Commented:
Perhaps I'm going *way* down the wrong track. Please bear with me as I am new to vb.net.

Basically I'm trying to convert an ms access database to vb.net. In Access I can assign a combobox with three columns and just select the value of the third column. I don't know what the equivalent is here

The datasource for the combobox has three columns SuburbID, Suburb, & postcodeID, The combobox value is set to suburbID which is what I want but I am using the combobox to proccess two values. The SuburbID (which I know how to get) and the postcodeID ( what I don't know how to get).

At the moment I am finding the whole dataset/datatables/binding/mappings/etc a tad confusing.
0
 
vbturboCommented:
try check this upload ive made for you

https://filedb.experts-exchange.com/incoming/ee-stuff/7185-TestCBO.zip 

vbturbo
0
 
PhillOAuthor Commented:
Absolutely Brilliant!! Thanks
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

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