Version

LimitToList Property

Gets/sets a value indicating whether the control will retain focus upon validation whenever the entered value is not a value in the control's ValueList
Syntax
'Declaration
 
Public Property LimitToList As Boolean
public bool LimitToList {get; set;}
Remarks

An ItemNotInList event will fire before the Validating event of the control whenever the text value entered into the editor portion of the control is not a value in the control’s valuelist. If true The LimitToList property will cancel the validating event and return focus whenever the entered value is not in the list.

Example
A LimitToList property, an ItemNotInList event, and overloaded IsItemInList methods provide convenient and flexible validation strategies for the UltraComboEditor.

For an overview of how to handle events in Visual Basic or Visual C#, see Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see Consuming Events in the .NET Framework Developer's Guide.

' 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" );
     }
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also