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?
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"))
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:
cmWorkOrder = CType(Me.BindingContext(dsAccess.Tables(0)), CurrencyManager)
I then added this code:
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?