ListView.AfterLabelEdit 이벤트

정의

사용자가 항목에 대한 레이블을 편집할 때 발생합니다.

public:
 event System::Windows::Forms::LabelEditEventHandler ^ AfterLabelEdit;
public event System.Windows.Forms.LabelEditEventHandler AfterLabelEdit;
public event System.Windows.Forms.LabelEditEventHandler? AfterLabelEdit;
member this.AfterLabelEdit : System.Windows.Forms.LabelEditEventHandler 
Public Custom Event AfterLabelEdit As LabelEditEventHandler 

이벤트 유형

예제

다음 코드 예제에서는 사용 하는 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

설명

AfterLabelEdit 사용자 완료 항목에 대 한 텍스트를 수정 하면 오류가 발생 합니다. 사용자가 항목에 대 한 새 문자열을 이벤트에 전달 하 고 이벤트 처리기에는 변경 사항을 거부할 수 있습니다. 변경 내용을 취소 하는 이벤트 처리기, 사용자 항목을 편집이 시작 되기 전의 텍스트에 텍스트를 되돌립니다.

참고

때문에 합니다 ListView.AfterLabelEdit 이벤트 수행 레이블 편집 호출 커밋되기 전에 ListView.Sort 이 이벤트 처리기에서 메서드는 원래 값을 사용 하 여 항목을 정렬 합니다.

되려면에서를 AfterLabelEdit 가 발생 하는 이벤트를 LabelEdit 의 속성을 ListView 제어 설정 해야 합니다 true.

사용자가 항목의 텍스트를 편집하기 전에 작업을 수행하기 위해 이벤트에 대한 BeforeLabelEdit 이벤트 처리기를 만들 수 있습니다.

이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생 을 참조하십시오.

적용 대상

추가 정보