Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm very inexperienced with regards to using databinding in VB.Net and am having a hard time resolving how to do what is probably really simple. I have a form with a combo box (used to select work order numbers) and a bunch of text boxes to display field information from the row associated with that work order number. My idea is to pull in the table into a dataset and then bind to the workorder table in that dataset. In the code below, I named my internal table "WorkOrders".

How do I get it so that you change the work order number in the combobox, that it will change the related data in the text boxes?

VB
Dim daAccess As OleDbDataAdapter
cnAccess.Open()
Dim SQL_RecentWorkOrders As String = "Select * from workorder where date>#" + dtToday.AddYears(-4).ToString + "# ORDER BY worknum DESC"
daAccess = New OleDbDataAdapter(SQL_RecentWorkOrders, cnAccess)
daAccess.Fill(dsAccess, "WorkOrders")
Dim dv As New DataView(dsAccess.Tables("WorkOrders"))
'Bind Work Orders
WorkOrderNumberCbo.DataBindings.Add("Text", dsAccess.Tables(0), "worknum")

WorkOrderNumberCbo.DataSource = dsAccess.Tables("WorkOrders").DefaultView
WorkOrderNumberCbo.DisplayMember = "worknum"
WorkOrderNumberCbo.ValueMember = "worknum"

CustIDTxt.DataBindings.Add("Text", dsAccess.Tables(0), "custid")
LastNameTxt.DataBindings.Add("Text", dsAccess.Tables(0), "operlast")
FirstNameTxt.DataBindings.Add("Text", dsAccess.Tables(0), "operfirst")
DescriptionTxt.DataBindings.Add("Text", dsAccess.Tables(0), "description")
AcresTxt.DataBindings.Add("Text", dsAccess.Tables(0), "acres")
GridSizeSelection.DataBindings.Add("Text", dsAccess.Tables(0), "grid")


Update: I figured out that I was handling the CurrencyManager wrong. After establishing a CurrencyManager object, I inserted the following line:
VB
cmWorkOrder = CType(Me.BindingContext(dsAccess.Tables(0)), CurrencyManager)


I then added this code:
VB
If IsNothing(cmWorkOrder) = False Then
    cmWorkOrder.Position = WorkOrderNumberCbo.SelectedIndex
    tmpText = WorkOrderNumberCbo.Text
End If


The problem I run into with this approach is that when I key in the value, while it does update the other fields correctly, it also has an annoying problem of moving the text for the most recently entered number to the top of the selection list, thereby hosing up all the relations based on position.

Can someone tell me how to disable this feature or at least how to change position in the CurrencyManager based on a primary key value instead?
Posted
Updated 1-Aug-11 9:46am
v3

1 solution

I found the root cause of the issue with the list changing. Once I removed the explicit binding of the Combo Box to the same Data Source as used for the Display Member, my problem went away. I would like to make it update the fields as the Auto-Complete suggests items, but that doesn't happen until the user clicks away. I may be using the wrong event.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900