共用方式為


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 集合中擷取此專案,這可讓您存取項目的屬性。

適用於

另請參閱