Solved

Binding Sources Navigation

Posted on 2008-06-19
6
202 Views
Last Modified: 2010-04-23
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
Comment
Question by:PhillO
  • 3
  • 3
6 Comments
 
LVL 18

Expert Comment

by:vbturbo
ID: 21832116
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
 

Author Comment

by:PhillO
ID: 21832539
Thanks for the reply

But how do I retrieve the actual postcodeid from the selected row
0
 
LVL 18

Expert Comment

by:vbturbo
ID: 21832724
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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

Author Comment

by:PhillO
ID: 21832901
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
 
LVL 18

Accepted Solution

by:
vbturbo earned 500 total points
ID: 21833206
try check this upload ive made for you

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

vbturbo
0
 

Author Comment

by:PhillO
ID: 21835738
Absolutely Brilliant!! Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question