VB.NET的一句代码不理解高手请进!!

来源:百度知道 编辑:UC知道 时间:2024/06/06 02:21:18
Dim fg As Boolean
Dim cm As CurrencyManager

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Me.Panel1.Visible = False
Me.da.Fill(Me.ds, "publishers")
Me.cm = Me.BindingContext(Me.ds, "publishers")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
已经用可视化方式配置了da as SqlDataAdapter、sqlconnection、ds(数据集)
怎么理解Me.cm = Me.BindingContext(Me.ds, "publishers")这句话
谢谢大家了!

CurrencyManager 从 BindingManagerBase 类派生。使用 BindingContext 返回一个 CurrencyManager 或一个 PropertyManager。返回的实际对象取决于传递给 BindingContext 的 Item 属性的数据源和数据成员。如果数据源是只能返回单个属性的对象(而不是对象列表),该类型则为 PropertyManager。例如,如果指定一个 TextBox 作为数据源,则将返回一个 PropertyManager。另一方面,如果数据源是实现 IList、IListSource 或 IBindingList 接口的对象,则返回 CurrencyManager。

Current 属性返回基础列表中的当前项。若要更改当前项,请将 Position 属性设置为新值。该值必须大于 0 而小于 Count 属性值。

如果基础数据源实现 IBindingList 接口,并且 AllowNew 属性设置为 true,则可以使用 AddNew 方法。

示例
下面的代码示例将一个 TextBox 控件绑定到 DataTable 中的一列,获取该绑定的 CurrencyManager,并设置其位置。

Visual Basic 复制代码' Place the next line into the Declarations section of the form.
Private myCurrencyManager As CurrencyManager

Private Sub BindControl(myTable As DataTable)
' Bind a TextBox control to a DataTable column in a DataSet.
TextBox1.DataBindings.Add("Text", myTable, "CompanyName")
' Specify the CurrencyManager for the DataTa