Property Binding

J

Jeremy Cowles

I have the following:
a combo box, cboPrinterType
a DataSet, dsPrinterTypes
a second DataSet, dsPrinter

I want to have the combo box list the values in dsPrinterTypes, so I have
set the DisplayMember and Data Source - this works
Next I want to have the selected item in the combo box bound to dsPrinter -
this does not work.

I have tried the following:
cboPrinterType.DataBindings.Add("Text", dsPrinter.Tables(0), "printer_type")

cboPrinterType.DataBindings.Add("SelectedItem", dsPrinter.Tables(0),
"printer_type")

cboPrinterType.DataBindings.Add("SelectedValue", dsPrinter.Tables(0),
"printer_type")



None of which work. The displayed items & values listed in the combo are
text.



Any suggestions?


TIA,
Jeremy
 
K

Kathleen Dollard

Jeremy,

What happens when it "doesn't work"? If it's out of sync with other controls
on the form, you'll have to show us how you bound them as well.

Kathleen
 
J

Jeremy Cowles

Yes, it does not select the actual value that comes from the database, it
just selects the first value in the list. If i make the combo editable (as
it is by default), and then I bind the "Text" property, it works fine
(meaning: it shows/selects the proper value from the list).

This behaviour has nothing to do with other controls, but as you requested,
I have posted my binding routines.

Thanks for the reply



Private Sub BindControls()

Me.cboConnection.DataSource = dsConnType.Tables(0)

Me.cboConnection.DisplayMember = "connection_type"

Me.cboConnection.ValueMember = "connection_type"

Me.cboConnection.DataBindings.Add("Text", dsPrinter.Tables(0),
"connection_type")

Me.cboType.DataSource = dsPrintType.Tables(0)

Me.cboType.DisplayMember = "printer_type"

Me.cboType.ValueMember = "printer_type"

Me.cboType.DataBindings.Add("Text", dsPrinter.Tables(0), "printer_type")

Me.txtPrinterID.DataBindings.Add("Text", dsPrinter.Tables(0),
"printer_id")

Me.txtDescription.DataBindings.Add("Text", dsPrinter.Tables(0),
"description")

Me.txtIPAddress.DataBindings.Add("Text", dsPrinter.Tables(0),
"ip_address")

Me.txtIPPort.DataBindings.Add("Text", dsPrinter.Tables(0), "ip_port")

Me.txtLocalPort.DataBindings.Add("Text", dsPrinter.Tables(0),
"local_port")

End Sub



Private Sub UnbindControls()

cboConnection.DisplayMember = ""

cboConnection.ValueMember = ""

Me.cboConnection.DataBindings.Clear()

Me.cboConnection.DataSource = Nothing

cboType.DisplayMember = ""

cboType.ValueMember = ""

Me.cboType.DataBindings.Clear()

Me.cboType.DataSource = Nothing

Me.txtPrinterID.DataBindings.Clear()

Me.txtDescription.DataBindings.Clear()

Me.txtIPAddress.DataBindings.Clear()

Me.txtIPPort.DataBindings.Clear()

Me.txtLocalPort.DataBindings.Clear()

End Sub



Jeremy
 

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