D
Dany P. Wu
Hi everyone,
As usual, weekend is tinkering time for students and I'm playing with
combobox databinding for the first time. Previously I have always iterated
through the records and added each item in the rows manually. Just thought
it would be nice to do it properly for a change.
Here's the bit of code I experiment with:
============================================================================
========================
Private Sub Create_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
txtResDate.Text = Date.Today
Dim command1 As New OleDb.OleDbCommand("select code, location from
airport where code in (select
distinct orig from flight)", con)
Dim daOrig As New OleDb.OleDbDataAdapter(command1)
Dim dest As New DataSet
Dim orig As New DataSet
Try
con.Open()
orig.Clear()
daOrig.Fill(orig)
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
With cboOrig
.DataSource = orig.Tables(0).DefaultView
.DisplayMember = "Location"
'.ValueMember = "Code"
End With
End Sub
===========================================================================
It seemed to only partially work. The combobox had the correct number of
items but each item was displayed as "System.Data.DataRowView", instead of
the actual value.
I also had to comment out the setting of the ValueMember property as I got
the error "Could not bind to the new display member." I'm a bit stumped as
to why this doesn't work. I've scrounged around the net for examples, etc.
but they generally point to this type of code. Did I miss something?
Any suggestions would be greatly appreciated.
Cheers,
Dany.
As usual, weekend is tinkering time for students and I'm playing with
combobox databinding for the first time. Previously I have always iterated
through the records and added each item in the rows manually. Just thought
it would be nice to do it properly for a change.
Here's the bit of code I experiment with:
============================================================================
========================
Private Sub Create_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
txtResDate.Text = Date.Today
Dim command1 As New OleDb.OleDbCommand("select code, location from
airport where code in (select
distinct orig from flight)", con)
Dim daOrig As New OleDb.OleDbDataAdapter(command1)
Dim dest As New DataSet
Dim orig As New DataSet
Try
con.Open()
orig.Clear()
daOrig.Fill(orig)
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
With cboOrig
.DataSource = orig.Tables(0).DefaultView
.DisplayMember = "Location"
'.ValueMember = "Code"
End With
End Sub
===========================================================================
It seemed to only partially work. The combobox had the correct number of
items but each item was displayed as "System.Data.DataRowView", instead of
the actual value.
I also had to comment out the setting of the ValueMember property as I got
the error "Could not bind to the new display member." I'm a bit stumped as
to why this doesn't work. I've scrounged around the net for examples, etc.
but they generally point to this type of code. Did I miss something?
Any suggestions would be greatly appreciated.
Cheers,
Dany.