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 элемента управления, что позволяет получить доступ к свойствам элемента.