需要了解绑定的帮助-如何链接绑定的控件? [英] Need help understanding bindings - how do you link bound controls?

查看:54
本文介绍了需要了解绑定的帮助-如何链接绑定的控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对在VB.Net中使用数据绑定非常缺乏经验,并且很难解决如何做可能非常简单的事情.我有一个带有组合框(用于选择工单号)和一堆文本框的表单,用于显示与该工单号关联的行中的字段信息.我的想法是将表放入数据集中,然后绑定到该数据集中的工作单表.在下面的代码中,我将内部表命名为"WorkOrders".

如何获取它,以便您更改组合框中的工单号,从而更改文本框中的相关数据?

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"))
'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")



更新:我发现我对CurrencyManager的处理不正确.建立CurrencyManager对象后,我插入了以下行:



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



我使用这种方法遇到的问题是,当我键入值时,虽然它确实正确更新了其他字段,但同时也存在一个令人讨厌的问题,即将最近输入的数字的文本移到选择列表的顶部,从而根据位置建立所有关系.

有人可以告诉我如何禁用此功能,或者至少如何基于主键值更改CurrencyManager中的位置吗?



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?

推荐答案

我找到了造成此问题的根本原因列表更改的问题.一旦删除了组合框与用于显示成员的相同数据源的显式绑定,我的问题就消失了.我想让它根据自动完成"建议的项目来更新字段,但是直到用户单击后才会发生.我可能使用了错误的事件.
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.


这篇关于需要了解绑定的帮助-如何链接绑定的控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆