Simple Binding combo box problem

  • Thread starter Thread starter KevinW
  • Start date Start date
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
 
Hi,

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

Ken
 
Back
Top