ListView.OnAfterLabelEdit(LabelEditEventArgs) 메서드

정의

AfterLabelEdit 이벤트를 발생시킵니다.

protected:
 virtual void OnAfterLabelEdit(System::Windows::Forms::LabelEditEventArgs ^ e);
protected virtual void OnAfterLabelEdit (System.Windows.Forms.LabelEditEventArgs e);
abstract member OnAfterLabelEdit : System.Windows.Forms.LabelEditEventArgs -> unit
override this.OnAfterLabelEdit : System.Windows.Forms.LabelEditEventArgs -> unit
Protected Overridable Sub OnAfterLabelEdit (e As LabelEditEventArgs)

매개 변수

e
LabelEditEventArgs

이벤트 데이터를 포함하는 LabelEditEventArgs입니다.

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 사전의 AfterLabelEdit 문자로 새로 편집 된 레이블을 제한 하는 이벤트입니다. 이 예제에서는 클래스를 ASCIIEncoding 사용하여 새 레이블의 각 문자에 대한 ASCII 문자 코드를 가져옵니다. 문자가 숫자를 나타내는 ASCII 코드 사이에 있으면 새 레이블을 항목에 적용할 수 없습니다. 이 예제에서는 폼에 컨트롤을 ListView 만들고 항목을 추가해야 합니다. 이 예제에서는 예제 코드에 AfterLabelEdit 정의된 이벤트 처리기에 이벤트를 연결해야 합니다. 클래스를 ASCIIEncoding 사용하려면 파일에 네임스페이스가 System.Text 포함되어야 합니다.

private:
   void MyListView_AfterLabelEdit( Object^ /*sender*/, System::Windows::Forms::LabelEditEventArgs^ e )
   {
      // Determine if label is changed by checking for 0.
      if ( e->Label == nullptr )
               return;

      // ASCIIEncoding is used to determine if a number character has been entered.
      ASCIIEncoding^ AE = gcnew ASCIIEncoding;

      // Convert the new label to a character array.
      array<Char>^temp = e->Label->ToCharArray();

      // Check each character in the new label to determine if it is a number.
      for ( int x = 0; x < temp->Length; x++ )
      {
         // Encode the character from the character array to its ASCII code.
         array<Byte>^bc = AE->GetBytes( temp[ x ].ToString() );

         // Determine if the ASCII code is within the valid range of numerical values.
         if ( bc[ 0 ] > 47 && bc[ 0 ] < 58 )
         {
            // Cancel the event and return the lable to its original state.
            e->CancelEdit = true;

            // Display a MessageBox alerting the user that numbers are not allowed.
            MessageBox::Show( "The text for the item cannot contain numerical values." );

            // Break out of the loop and exit.
            return;
         }
      }
   }
private void MyListView_AfterLabelEdit(object sender, System.Windows.Forms.LabelEditEventArgs e)
{
 
   // Determine if label is changed by checking for null.
   if (e.Label == null)
      return;

   // ASCIIEncoding is used to determine if a number character has been entered.
   ASCIIEncoding AE = new ASCIIEncoding();
   // Convert the new label to a character array.
   char[] temp = e.Label.ToCharArray();

   // Check each character in the new label to determine if it is a number.
   for(int x=0; x < temp.Length; x++)
   {
      // Encode the character from the character array to its ASCII code.
      byte[] bc = AE.GetBytes(temp[x].ToString());
   
      // Determine if the ASCII code is within the valid range of numerical values.
      if(bc[0] > 47 && bc[0] < 58)
      {
         // Cancel the event and return the lable to its original state.
         e.CancelEdit = true;
         // Display a MessageBox alerting the user that numbers are not allowed.
         MessageBox.Show ("The text for the item cannot contain numerical values.");
         // Break out of the loop and exit.
         return;
      }
   }
}
Private Sub MyListView_AfterLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.LabelEditEventArgs) Handles listView1.AfterLabelEdit

   ' Determine if label is changed by checking to see if it is equal to Nothing.
   If e.Label Is Nothing Then
      Return
   End If
   ' ASCIIEncoding is used to determine if a number character has been entered.
   Dim AE As New ASCIIEncoding()
   ' Convert the new label to a character array.
   Dim temp As Char() = e.Label.ToCharArray()

   ' Check each character in the new label to determine if it is a number.
   Dim x As Integer
   For x = 0 To temp.Length - 1
      ' Encode the character from the character array to its ASCII code.
      Dim bc As Byte() = AE.GetBytes(temp(x).ToString())

      ' Determine if the ASCII code is within the valid range of numerical values.
      If bc(0) > 47 And bc(0) < 58 Then
         ' Cancel the event and return the lable to its original state.
         e.CancelEdit = True
         ' Display a MessageBox alerting the user that numbers are not allowed.
         MessageBox.Show("The text for the item cannot contain numerical values.")
         ' Break out of the loop and exit.
         Return
      End If
   Next x
End Sub

설명

이벤트가 발생하면 대리자를 통해 이벤트 처리기가 호출됩니다. 자세한 내용은 이벤트 처리 및 발생합니다.

또한 OnAfterLabelEdit 메서드를 사용하면 파생 클래스가 대리자를 연결하지 않고도 이벤트를 처리할 수 있습니다. 이는 파생 클래스에서 이벤트를 처리하는 기본 방법입니다.

상속자 참고

파생 클래스에서 OnAfterLabelEdit(LabelEditEventArgs)를 재정의하는 경우 등록된 대리자가 이벤트를 받도록 기본 클래스의 OnAfterLabelEdit(LabelEditEventArgs) 메서드를 호출해야 합니다.

적용 대상

추가 정보