Simple Binding combo box problem

K

KevinW

Imports System.Data.OleDb
Imports System
Imports System.Data
Imports System.Data.Common
Imports System.Windows.Forms

Public Class Form1
Inherits System.Windows.Forms.Form

I am trying to simple bind a combo box to a data source per the code
below in the load procedure. It does not produce any result on the
combo box. The code for the text box works fine and the code for the
combo box will work if I change the property from SelectedValue to
Text. Any suggestions?



Dim conStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;data
source=c:\\northwind.mdb"

Dim conn As New OleDbConnection(conStr)
Dim sqlStr As String = "SELECT * FROM Orders"
Dim da As New OleDbDataAdapter(sqlStr, conn)
Dim ds As New DataSet
Dim kwds As New DataSet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

da.Fill(kwds, "Orders")
Dim bmbOrders As BindingManagerBase
bmbOrders = Me.BindingContext(kwds, "Orders")
TextBox1.DataBindings.Add("Text", kwds, "Orders.CustomerID")
ComboBox2.DataBindings.Add("SelectedValue", kwds,
"Orders.CustomerID")
ComboBox2.ValueMember = "ShipCity"

End Sub
 
K

Ken Tucker [MVP]

Hi,

Combobox2.DataSource = kwds.Tables("Orders")
Combobox2.DisplayMember = "ShipCity"
Combobox2.ValueMember = "CustomerID"

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top