Version

SelLength Property

Returns or sets the number of characters selected in a cell being edited.
Syntax
'Declaration
 
Public Property SelLength As Integer
public int SelLength {get; set;}
Remarks

This property, in conjunction with the SelStart and SelText properties, is useful for tasks such as setting the insertion point, establishing an insertion range, selecting substrings, or clearing text in the cell being edited.

The valid range for this property is 0 to the length of the cell text. Attempting to set this property to a value outside that range will reset this property to the highest acceptable value.

This property can only be set or retrieved when the control is in edit mode, which can be determined by using the IsInEditMode property. If the control is in edit mode, the ActiveCell property can be used to determine which cell is currently being edited. If the control is not in edit mode, attempting to use this property will generate an error.

Example
Following code demonstrates SelStart, SelText, and SelLength properties off the UltraGridCell. They are only supported while the cell is in edit mode and the underlying embeddable editor supports text selection. Most editors support text selection however editors like CheckEditor or OptionSetEditor do not support text selection. The cell throws an exception if these conditions are not met.

Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid
Imports System.Diagnostics

   Private Sub Func()

       Dim activeCell As UltraGridCell = Me.UltraGrid1.ActiveCell

       ' Ensure that a cell is in edit mode before accessing any of these properties.
       ' Otherwise the cell will throw an exception since these properties only make
       ' sense if the cell is in edit mode.
       If activeCell Is Nothing OrElse Not activeCell.IsInEditMode Then
           Debug.WriteLine("There is no cell in edit mode.")
           Return
       End If

       ' Ensure that the editor being used for editing the cell supports text selection.
       ' Otherwise the cell will throw an exception since these properties only make
       ' sense for editors that support text selection.
       If Not activeCell.Column.Editor.SupportsSelectableText Then
           Debug.WriteLine("The Editor being used for editing the cell doesn't support text selection.")
           Return
       End If

       ' Write out the values of SelStart, SelLength and SelText properties.
       Debug.WriteLine("Selection start	= " & activeCell.SelStart)
       Debug.WriteLine("Selection length	= " & activeCell.SelLength)
       Debug.WriteLine("Selected text		= " & activeCell.SelText)

       ' You can also set these properties. Setting the SelStart positions the caret at the 
       ' specified character position.
       activeCell.SelStart = 0

       ' Setting the SelLength to a non-zero value selects text starting from SelStart position.
       activeCell.SelLength = activeCell.Column.Editor.TextLength

       ' You can set the SelText to replace the currently selected text.
       activeCell.SelText = "Replacement Text"

   End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;

private void func( )
{

	UltraGridCell activeCell = this.ultraGrid1.ActiveCell;

	// Ensure that a cell is in edit mode before accessing any of these properties.
	// Otherwise the cell will throw an exception since these properties only make
	// sense if the cell is in edit mode.
	if ( null == activeCell || !activeCell.IsInEditMode )
	{
		Debug.WriteLine( "There is no cell in edit mode." );
		return;
	}

	// Ensure that the editor being used for editing the cell supports text selection.
	// Otherwise the cell will throw an exception since these properties only make
	// sense for editors that support text selection.
	if ( !activeCell.Column.Editor.SupportsSelectableText )
	{
		Debug.WriteLine( "The Editor being used for editing the cell doesn't support text selection." );
		return;
	}

	// Write out the values of SelStart, SelLength and SelText properties.
	Debug.WriteLine( "Selection start	= " + activeCell.SelStart );
	Debug.WriteLine( "Selection length	= " + activeCell.SelLength );
	Debug.WriteLine( "Selected text		= " + activeCell.SelText );

	// You can also set these properties. Setting the SelStart positions the caret at the 
	// specified character position.
	activeCell.SelStart = 0;

	// Setting the SelLength to a non-zero value selects text starting from SelStart position.
	activeCell.SelLength = activeCell.Column.Editor.TextLength;

	// You can set the SelText to replace the currently selected text.
	activeCell.SelText = "Replacement Text";

}
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