ListView.OnAfterLabelEdit メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim e As LabelEditEventArgs Me.OnAfterLabelEdit(e)

イベントが発生すると、デリゲートを使用してイベント ハンドラが呼び出されます。詳細については、「イベントの発生」を参照してください。
OnAfterLabelEdit メソッドを使用すると、デリゲートを結び付けずに、派生クラスでイベントを処理することもできます。派生クラスでイベントを処理する場合は、この手法をお勧めします。
継承時の注意 派生クラスで OnAfterLabelEdit をオーバーライドする場合は、登録されているデリゲートがイベントを受け取ることができるように、基本クラスの OnAfterLabelEdit メソッドを呼び出してください。
AfterLabelEdit イベントを使用して、新しく編集するラベルの文字をアルファベットに制限する方法を次のコード例に示します。この例では、ASCIIEncoding クラスを使用して、新しいレベルの各文字の ASCII 文字コードを取得しています。この文字が数字を表す ASCII コードの場合、新しいラベルは項目には適用できません。この例では、フォーム上に ListView コントロールが作成され、そのコントロールに項目が追加されている必要があります。また、AfterLabelEdit イベントが、この例で定義されているイベント ハンドラに接続されている必要もあります。ASCIIEncoding クラスを使用するには、ファイルに System.Text 名前空間が含まれている必要があります。
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 = 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
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: 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.get_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.get_Label().ToCharArray(); // Check each character in the new label to determine if it is a number. for (int x = 0; x < temp.get_Length(); x++) { // Encode the character from the character array to its ASCII code. ubyte bc[] = ae.GetBytes(temp.get_Item(x).ToString()); // Determine if the ASCII code is within the valid range // of numerical values. if (Convert.ToInt32(bc.get_Item(0)) > 47 && Convert.ToInt32(bc.get_Item(0)) < 58) { // Cancel the event and return the lable to its original state. e.set_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; } } } //MyListView_AfterLabelEdit

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からListView.OnAfterLabelEdit メソッドを検索する場合は、下記のリンクをクリックしてください。

- ListView.OnAfterLabelEdit メソッドのページへのリンク