BindingSource.ResetBindings(Boolean) Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Causes a control bound to the BindingSource to reread all the items in the list and refresh their displayed values.
public:
void ResetBindings(bool metadataChanged);
public void ResetBindings (bool metadataChanged);
member this.ResetBindings : bool -> unit
Public Sub ResetBindings (metadataChanged As Boolean)
- metadataChanged
- Boolean
true
if the data schema has changed; false
if only values have changed.
The following code example uses a BindingSource component to bind an array list, which does not provide change notification. An item is removed from the list, and the bound controls are notified of the change by calling the ResetBindings method. This code example is part of a larger example provided in How to: Reflect Data Source Updates in a Windows Forms 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
The ResetBindings method informs all controls bound to the BindingSource to refresh their values. The method does this by raising the ListChanged event at least once; the metaDataChanged
parameter indicates the nature of the underlying change.
A
metaDataChanged
value oftrue
indicates that the data schema of BindingSource has changed. A ListChanged event is raised with ListChangedEventArgs.ListChangedType set to ListChangedType.PropertyDescriptorChanged.A
metaDataChanged
value offalse
indicates that only the values of one or more items have changed.
Regardless of the value of metaDataChanged
, a ListChanged event is raised with ListChangedEventArgs.ListChangedType set to ListChangedType.Reset. As a consequence, calling ResetBindings with a parameter of true
will raise two ListChanged events.
ResetBindings is automatically called whenever another member makes major changes to the data-binding, such as setting the DataSource or DataMember properties. However, the programmer can also call this method explicitly.
Product | Versions |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: