バージョン

ItemNotInList イベント

コントロールのエディター部分に入力されたテキスト値がコントロールの値リストに含まれない場合に、Validating イベントの前に発生します。
シンタックス
'宣言
 
Public Event ItemNotInList As UltraComboEditor.ItemNotInListEventHandler
public event UltraComboEditor.ItemNotInListEventHandler ItemNotInList
イベント データ

イベント ハンドラが、このイベントに関連するデータを含む、Infragistics.Win.UltraWinEditors.ValidationErrorEventArgs 型の引数を受け取りました。次の ValidationErrorEventArgs プロパティには、このイベントの固有の情報が記載されます。

プロパティ解説
Beep  
InvalidText  
LastValidValue  
RetainFocus  
解説

ItemNotInList イベントは、コントロールの ValueList にない値でフォーカスを失った時にコントロールが反応する方法をカスタマイズする機能を提供します。

Infragistics.Win.UltraWinEditors.ValidationErrorEventArgs クラスは、これを行うために以下のプロパティを公開します。

  • Infragistics.Win.UltraWinEditors.ValidationErrorEventArgs.Beep: True に設定すると、コントロールの ValueList にない値でフォーカスを失った時にコントロールはビープ音を発します。デフォルト値は False です。
  • Infragistics.Win.UltraWinEditors.ValidationErrorEventArgs.RetainFocus: True に設定すると、有効値が入力されるまでコントロールは入力フォーカスを保持します。デフォルト値は False です。コントロールの LimitToList プロパティが True に設定されると、RetainFocus のデフォルト値は True になります。
  • Infragistics.Win.UltraWinEditors.ValidationErrorEventArgs.LastValidValue: コントロールによって保持された最終の有効値を含みます。以前の値がコントロールの ValueList に存在しなければ、LastValidValue は null になります。ユーザー フィードバックを提供するために有用で、コントロールを有効な状態にします。

使用例
' LimitToList property
Private Sub Form1_Load(sender As Object, e As System.EventArgs)
 
' The LimitToList property specifies whether the UltraComboEditor will retain focus upon
' validation whenever the entered value is not a value in the control's ValueList.
Me.ultraComboEditor1.LimitToList = True

End Sub 'Form1_Load


' ItemNotInList event
Private Sub ultraComboEditor1_ItemNotInList(sender As Object, e As Infragistics.Win.UltraWinEditors.ValidationErrorEventArgs)

' The ItemNotInList event is fired before the Validating event of the UltraComboEditor whenever
' the text value entered into the editor portion of the control is not a value in the control’s
' ValueList.  The event passes a ValidationErrorEventArgs object that contains InvalidText
' and LastValidValue properties as well as properties for specifying that the UltraComboEditor
' should retain focus or beep to provide an auditory cue.

' Specifies whether the control will retain focus. Overrides the UltraComboEditor's LimitToList
' property if RetainFocus is set to false.
e.RetainFocus = True
   
' Provide an auditory cue that the enetered text is invalid.  If a message box is used this will be
' unnecesary since the message box will provide a beep.
e.Beep = True
   
' Display a message box indicating that the entered text is invalid.
MessageBox.Show(e.InvalidText + " is not a valid value.", "Invalid Entry")
   
' Restore a previously valid value if one was entered, otherwise set a valid default value.
If Not (e.LastValidValue Is Nothing) Then
    Me.ultraComboEditor1.Value = e.LastValidValue
Else
    Me.ultraComboEditor1.SelectedItem = Me.ultraComboEditor1.Items(0)
End If

End Sub 'ultraComboEditor1_ItemNotInList


' IsItemInList overloaded methods
Private Sub button1_Click(sender As Object, e As System.EventArgs)

' The IsItemInList overloaded methods return a boolean indicating whether the value of the
' UltraComboEditor's Text property, or a specified string, is a value in the control's ValueList.
' This provides a convenient way to perform validation in code.

' If the current value of the UltraComboEditor's Text property is not a value in the control's
' ValueList assign a valid text value.
Dim currentTextIsValid As Boolean = Me.ultraComboEditor1.IsItemInList()
If Not currentTextIsValid Then
    Me.ultraComboEditor1.Text = "Some valid text value"
End If 

' If the specified string is not a value in the UltraComboEditor's ValueList assign a valid text value.
Dim someText As String = "Some Text"
Dim itemIsInList As Boolean = Me.ultraComboEditor1.IsItemInList(someText)
   
If itemIsInList Then
    Me.ultraComboEditor1.Text = someText
Else
    System.Diagnostics.Debug.WriteLine((someText + " is not in the list"))
End If

End Sub 'button1_Click
// LimitToList property
     private void Form1_Load(object sender, System.EventArgs e)
     {
         this.ultraComboEditor1.Items.Add( "One" );
         this.ultraComboEditor1.Items.Add( "Two" );
         this.ultraComboEditor1.Items.Add( "Three" );
         this.ultraComboEditor1.Items.Add( "Four" );

         // The LimitToList property specifies whether the UltraComboEditor will retain focus upon
         // validation whenever the entered value is not a value in the control's ValueList.
         this.ultraComboEditor1.LimitToList = true;
     }

// ItemNotInList event
     private void ultraComboEditor1_ItemNotInList(object sender, Infragistics.Win.UltraWinEditors.ValidationErrorEventArgs e)
     {
         // The ItemNotInList event is fired before the Validating event of the UltraComboEditor whenever
         // the text value entered into the editor portion of the control is not a value in the control’s
         // ValueList.  The event passes a ValidationErrorEventArgs object that contains InvalidText
         // and LastValidValue properties as well as properties for specifying that the UltraComboEditor
         // should retain focus or beep to provide an auditory cue.

         // Specifies whether the control will retain focus. Overrides the UltraComboEditor's LimitToList
         // property if RetainFocus is set to false.
         e.RetainFocus = true;

         // Provide an auditory cue that the enetered text is invalid.  If a message box is used this will be
         // unnecesary since the message box will provide a beep.
         e.Beep = true;

         // Display a message box indicating that the entered text is invalid.
         MessageBox.Show( e.InvalidText + " is not a valid value.", "Invalid Entry" );

         // Restore a previously valid value if one was entered, otherwise set a valid default value.
         if ( e.LastValidValue != null )
             this.ultraComboEditor1.Value = e.LastValidValue;
         else
             this.ultraComboEditor1.SelectedItem = this.ultraComboEditor1.Items[0];

     }    

// IsItemInList overloaded methods
     private void button1_Click(object sender, System.EventArgs e)
     {
         // The IsItemInList overloaded methods return a boolean indicating whether the value of the
         // UltraComboEditor's Text property, or a specified string, is a value in the control's ValueList.
         // This provides a convenient way to perform validation in code.

         // If the current value of the UltraComboEditor's Text property is not a value in the control's
         // ValueList assign a valid text value.
         bool currentTextIsValid = this.ultraComboEditor1.IsItemInList();
         if ( !currentTextIsValid )
             this.ultraComboEditor1.Text = "Some valid text value";

         // If the specified string is not a value in the UltraComboEditor's ValueList assign a valid text value.
         string someText = "Some Text";
         bool itemIsInList = this.ultraComboEditor1.IsItemInList( someText );

         if( itemIsInList )
             this.ultraComboEditor1.Text = someText;
         else
             System.Diagnostics.Debug.WriteLine( someText + " is not in the list" );
     }
参照