Solved

Binding Sources Navigation

Posted on 2008-06-19
6
196 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now