BindingSource.ResetItem(Int32) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
使绑定到 BindingSource 的控件重新读取指定索引处的项,并刷新其显示值。
public:
void ResetItem(int itemIndex);
public void ResetItem (int itemIndex);
member this.ResetItem : int -> unit
Public Sub ResetItem (itemIndex As Integer)
参数
- itemIndex
- Int32
已更改的项的从零开始的索引。
示例
下面的代码示例使用 组件 BindingSource 将列表绑定到控件 DataGridView 。 列表不会引发更改通知,因此 ResetItem , 上的 BindingSource 方法用于引发 ListChanged 事件。 此代码示例是 如何:使用 BindingSource ResetItem 方法引发更改通知中提供的更大示例的一部分。
// This event handler changes the value of the CompanyName
// property for the first item in the list.
void changeItemBtn_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
// Get a reference to the list from the BindingSource.
List< DemoCustomer^ >^ customerList =
static_cast<List< DemoCustomer^ >^>(
this->customersBindingSource->DataSource);
// Change the value of the CompanyName property for the
// first item in the list.
customerList->default[ 0 ]->CompanyName = L"Tailspin Toys";
// Call ResetItem to alert the BindingSource that the
// list has changed.
this->customersBindingSource->ResetItem( 0 );
}
// This event handler changes the value of the CompanyName
// property for the first item in the list.
void changeItemBtn_Click(object sender, EventArgs e)
{
// Get a reference to the list from the BindingSource.
List<DemoCustomer> customerList =
this.customersBindingSource.DataSource as List<DemoCustomer>;
// Change the value of the CompanyName property for the
// first item in the list.
customerList[0].CompanyName = "Tailspin Toys";
// Call ResetItem to alert the BindingSource that the
// list has changed.
this.customersBindingSource.ResetItem(0);
}
' This event handler changes the value of the CompanyName
' property for the first item in the list.
Private Sub changeItemBtn_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles changeItemBtn.Click
' Get a reference to the list from the BindingSource.
Dim customerList As List(Of DemoCustomer) = _
CType(Me.customersBindingSource.DataSource, List(Of DemoCustomer))
' Change the value of the CompanyName property for the
' first item in the list.
customerList(0).CompanyName = "Tailspin Toys"
' Call ResetItem to alert the BindingSource that the
' list has changed.
Me.customersBindingSource.ResetItem(0)
End Sub
注解
方法 ResetItem 通知绑定到指定 Position 处的 项的所有控件刷新其值。 方法通过引发 ListChanged 设置为 的事件 ListChangedEventArgs.ListChangedType 来 ListChangedType.ItemChanged执行此操作。
ResetItem 每当对单个项的值进行更改时,都会自动调用 。 但是,程序员也可以显式调用此方法。