BindingSource.ResetBindings(Boolean) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
使绑定到 BindingSource 控件的控件重新读取列表中的所有项并刷新其显示的值。
public:
void ResetBindings(bool metadataChanged);
public void ResetBindings(bool metadataChanged);
member this.ResetBindings : bool -> unit
Public Sub ResetBindings (metadataChanged As Boolean)
参数
- metadataChanged
- Boolean
示例
下面的代码示例使用组件 BindingSource 绑定数组列表,该列表不提供更改通知。 从列表中删除项,绑定控件通过调用 ResetBindings 方法通知更改。 此代码示例是 How to: Reflect Data Source Updates in a Windows 窗体 Control with the BindingSource 中提供的大型示例的一部分。
private:
void button1_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
String^ xml = "<US><states>"
+ "<state><name>Washington</name><capital>Olympia</capital> "
+ "<flower>Coast Rhododendron</flower></state>"
+ "<state><name>Oregon</name><capital>Salem</capital>"
+ "<flower>Oregon Grape</flower></state>"
+ "<state><name>California</name><capital>Sacramento</capital>"
+ "<flower>California Poppy</flower></state>"
+ "<state><name>Nevada</name><capital>Carson City</capital>"
+ "<flower>Sagebrush</flower></state>"
+ "</states></US>";
// Convert the xml string to bytes and load into a memory stream.
array<Byte>^ xmlBytes = Encoding::UTF8->GetBytes( xml );
MemoryStream^ stream = gcnew MemoryStream( xmlBytes,false );
// Create a DataSet and load the xml into it.
dataSet2->ReadXml( stream );
// Set the data source.
bindingSource1->DataSource = dataSet2;
bindingSource1->ResetBindings( true );
}
private void button1_Click(object sender, EventArgs e)
{
// If items remain in the list, remove the first item.
if (states.Count > 0)
{
states.RemoveAt(0);
// Call ResetBindings to update the textboxes.
bindingSource1.ResetBindings(false);
}
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles button1.Click
' If items remain in the list, remove the first item.
If states.Count > 0 Then
states.RemoveAt(0)
' Call ResetBindings to update the textboxes.
bindingSource1.ResetBindings(False)
End If
End Sub
注解
该方法 ResetBindings 通知绑定到 BindingSource 刷新其值的所有控件。 该方法通过至少引发 ListChanged 事件一次来执行此操作;参数 metaDataChanged 指示基础更改的性质。
指示
metaDataChanged数据架构true已更改的值BindingSource。 将引发一个 ListChanged 事件,并 ListChangedEventArgs.ListChangedType 设置为 ListChangedType.PropertyDescriptorChanged.一个
metaDataChanged值false,指示仅更改了一个或多个项的值。
无论其值如何true将引发两ListChanged个事件。
ResetBindings 每当另一个成员对数据绑定进行重大更改(例如设置 DataSource 或 DataMember 属性)时,都会自动调用。 但是,程序员还可以显式调用此方法。