LabelEditEventArgs LabelEditEventArgs LabelEditEventArgs LabelEditEventArgs Class

定义

提供有关 BeforeLabelEditAfterLabelEdit 事件的数据。Provides data for the BeforeLabelEdit and AfterLabelEdit events.

public ref class LabelEditEventArgs : EventArgs
public class LabelEditEventArgs : EventArgs
type LabelEditEventArgs = class
    inherit EventArgs
Public Class LabelEditEventArgs
Inherits EventArgs
继承
LabelEditEventArgsLabelEditEventArgsLabelEditEventArgsLabelEditEventArgs

示例

下面的代码示例演示如何处理ListView.BeforeLabelEdit事件以及如何Item使用和CancelEdit属性。The following code example demonstrates handling the ListView.BeforeLabelEdit event and using the Item and CancelEdit properties. 若要运行该示例, 请将以下代码粘贴到包含ListView名为ListView1的控件的窗体中, 并至少填充3个项。To run the example, paste the following code in a form containing a ListView control named ListView1 and populated with at least 3 items. 确保所有事件都与其事件处理方法关联。Ensure all events are associated with their event-handling methods.

void ListView1_BeforeLabelEdit( Object^ sender,
   System::Windows::Forms::LabelEditEventArgs^ e )
{
   // Allow all but the first two items of the list to 
   // be modified by the user.
   if ( e->Item < 2 )
   {
      e->CancelEdit = true;
   }
}
private void ListView1_BeforeLabelEdit(object sender, 
	System.Windows.Forms.LabelEditEventArgs e)
{
	// Allow all but the first two items of the list to 
	// be modified by the user.
	if (e.Item<2)
	{
		e.CancelEdit = true;
	}
}

Private Sub ListView1_BeforeLabelEdit(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.LabelEditEventArgs) _
    Handles ListView1.BeforeLabelEdit

    ' Allow all but the first two items of the list to be modified by
    ' the user.
    If (e.Item < 2) Then
        e.CancelEdit = True
    End If
End Sub

注解

LabelEditEventArgs指定的ListViewItem索引和标题, 以及用户编辑后的标题。A LabelEditEventArgs specifies the index and caption of a ListViewItem and the caption after it has been edited by the user. 此类还提供CancelEdit属性。This class also provides a CancelEdit property. 您可以在ListView.BeforeLabelEdit事件处理程序中使用此属性来阻止用户编辑标签。You can use this property in a ListView.BeforeLabelEdit event handler to prevent the user from editing the label. 您还可以在ListView.AfterLabelEdit事件处理程序中使用它来还原更改, 并将其标签返回到其原始值。You can also use it in an ListView.AfterLabelEdit event handler to revert the change, returning the label it to its original value. 如果要在提交更改之前验证用户输入, 则此方法非常有用。This is useful when you want to validate user input before committing the change.

备注

由于在ListView.AfterLabelEdit提交标签编辑之前发生事件, 因此在此事件的ListView.Sort处理程序中调用方法将使用原始值对项进行排序。Because the ListView.AfterLabelEdit event takes place before the label edit is committed, calling the ListView.Sort method in a handler for this event will sort the item using the original value.

构造函数

LabelEditEventArgs(Int32) LabelEditEventArgs(Int32) LabelEditEventArgs(Int32) LabelEditEventArgs(Int32)

使用要编辑的 LabelEditEventArgs 的指定索引初始化 ListViewItem 类的新实例。Initializes a new instance of the LabelEditEventArgs class with the specified index to the ListViewItem to edit.

LabelEditEventArgs(Int32, String) LabelEditEventArgs(Int32, String) LabelEditEventArgs(Int32, String) LabelEditEventArgs(Int32, String)

使用正在被编辑的 LabelEditEventArgs 的指定索引和 ListViewItem 标签的新文本初始化 ListViewItem 类的新实例。Initializes a new instance of the LabelEditEventArgs class with the specified index to the ListViewItem being edited and the new text for the label of the ListViewItem.

属性

CancelEdit CancelEdit CancelEdit CancelEdit

获取或设置一个值,该值指示是否应取消对 ListViewItem 的标签所作的更改。Gets or sets a value indicating whether changes made to the label of the ListViewItem should be canceled.

Item Item Item Item

获取 ListViewItem(它包含要编辑的标签)的从零开始的索引。Gets the zero-based index of the ListViewItem containing the label to edit.

Label Label Label Label

获取分配给 ListViewItem 的标签的新文本。Gets the new text assigned to the label of the ListViewItem.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

适用于

另请参阅