ListViewEditEventArgs.NewEditIndex Vlastnost

Definice

Získá index položky, která se upravuje.

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

Hodnota vlastnosti

Int32

Index položky, která se upravuje.

Příklady

Následující příklad ukazuje, jak použít NewEditIndex vlastnost k načtení objektu ListViewItem , který se upravuje. Tento příklad kódu je součástí většího příkladu zadaného ListViewEditEventArgs pro třídu.

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

Poznámky

NewEditIndex Pomocí vlastnosti určete index položky, která se upravuje. Index položky se často používá k načtení této položky z Items kolekce ListView ovládacího prvku, který umožňuje přístup k vlastnostem položky.

Platí pro

Viz také