Data Binding to Textbox

P

Peter

Hi,

I'm trying to create a form that shows table rows in a listbox. Several
comboboxes expand the foreign key fields into text values from the parent
tables, and there are also some textboxes for the non-foreign key fields.
When the user clicks on a row in the listbox, the comboboxes' SelectedItem
changes to reflect the foreign key selections in the currently selected row.
That part is working fine. I also want the textboxes to change to reflect
the currently selected item's values.

I created a DataBinding in the textbox (actually, it's a custom control,
NumericTextBox, which only allows numeric values). The field that is bound
to the NumericTextBox is of type int. The property it is bound to (IntValue)
is of type Int32 (although I've tried many different types with no luck).
I've also tried using a plain textbox to no avail.

The problem is that, initially, the NumericTextBox displays the correct
value for the initially selected row. But if I enter that text box, I can't
leave it. And if I change the value of it, when I press tab, it changes back
to what it was. Also, if (before clicking it) I change to a different row in
the listbox, all the comboboxes update, but the textbox does not. What's
going on?

***
Private Sub PaperEditor_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Initialize data binding for listbox.
lbPaperSelector.DataSource = internalDataSet.Paper 'The main paper
table, with foreign keys galore.
lbPaperSelector.DisplayMember = "FullText"
lbPaperSelector.ValueMember = "ID"

'Set selected item to the first paper listed.
lbPaperSelector.SelectedIndex = 0

'Initialize combo boxes.


cbSupplier.DataSource = internalDataSet.Supplier 'The parent
tables to table Paper. Lots more of these in the actual code.
cbSupplier.DisplayMember = "Name"
cbSupplier.ValueMember = "ID"
cbSize.DataSource = internalDataSet.Size
cbSize.DisplayMember = "Name"
cbSize.ValueMember = "ID"

'Initialize text boxes.
tbItemNumber.DataBindings.Add("IntValue",
DirectCast(lbPaperSelector.SelectedItem, DataRowView).Row, "ItemNumber")
End Sub

Private Sub lbPaperSelector_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles lbPaperSelector.SelectedIndexChanged
'Update combo boxes.
cbSupplier.SelectedValue =
DirectCast(DirectCast(lbPaperSelector.SelectedItem, DataRowView).Row,
Papers.PaperRow).Supplier
cbSize.SelectedValue =
DirectCast(DirectCast(lbPaperSelector.SelectedItem, DataRowView).Row,
Papers.PaperRow).Size
End Sub
 

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