ListViewEditEventArgs.NewEditIndex 属性

定义

获取要编辑的项的索引。

public:
 property int NewEditIndex { int get(); };
public int NewEditIndex { get; }
member this.NewEditIndex : int
Public ReadOnly Property NewEditIndex As Integer

属性值

要编辑的项的索引。

示例

以下示例演示如何使用 NewEditIndex 属性检索 ListViewItem 正在编辑的对象。 此代码示例是为 ListViewEditEventArgs 类提供的一个更大示例的一部分。

void ProductsListView_ItemEditing(Object sender, ListViewEditEventArgs e)
{
  ListViewItem item = ProductsListView.Items[e.NewEditIndex];
  Label dateLabel = (Label)item.FindControl("DiscontinuedDateLabel");
  
  if (String.IsNullOrEmpty(dateLabel.Text))
    return;
  
  //Verify if the item is discontinued.
  DateTime discontinuedDate = DateTime.Parse(dateLabel.Text);
  if (discontinuedDate < DateTime.Now)
  {
    Message.Text = "You cannot edit a discontinued item.";
    e.Cancel = true;
    ProductsListView.SelectedIndex = -1;
  }       
}
Sub ProductsListView_ItemEditing(ByVal sender As Object, ByVal e As ListViewEditEventArgs)
  Dim item As ListViewItem = ProductsListView.Items(e.NewEditIndex)
  Dim dateLabel As Label = CType(item.FindControl("DiscontinuedDateLabel"), Label)
    
  If String.IsNullOrEmpty(dateLabel.Text) Then _
    Return
    
  'Verify if the item is discontinued.
  Dim discontinuedDate As DateTime = DateTime.Parse(dateLabel.Text)
  If discontinuedDate < DateTime.Now Then
    Message.Text = "You cannot edit a discontinued item."
    e.Cancel = True
    ProductsListView.SelectedIndex = -1
  End If
End Sub

注解

NewEditIndex使用 属性确定正在编辑的项的索引。 项索引通常用于从 Items 控件的 ListView 集合中检索此项,这使你能够访问项的属性。

适用于

另请参阅