This documentation is archived and is not being maintained.

TextSelection Interface

Provides access to view-based editing operations and selected text.

Namespace: EnvDTE
Assembly: EnvDTE (in envdte.dll)

public interface class TextSelection
/** @attribute GuidAttribute("1FA0E135-399A-4D2C-A4FE-D21E2480F921") */ 
public interface TextSelection
public interface TextSelection

The properties and methods of the TextSelection object directly reflect editor commands in the Visual Studio integrated development environment (IDE). Like the environment, text selection operations are affected by the editor's global state, such as whether it is in overwrite mode or virtual white space mode.

Any operation attempting to modify a text document fails if it affects any characters contained in a read-only block, or if the text document itself is read-only.

Some of the TextSelection object's properties and methods may fail if the associated document is an HTML document. Possible causes of the failure are: the windows that display the HTML document are not in Source view or the data behind the text document is locked.

Sub TextSelectionExample()
   ' Before running this example, open a text document.
   Dim objSel As TextSelection = DTE.ActiveDocument.Selection
   Dim objActive As VirtualPoint = objSel.ActivePoint
   ' Collapse the selection to the beginning of the line.
   ' objActive is "live", tied to the position of the actual selection, 
   ' so it will reflect the new position.
   Dim iCol As Long = objActive.DisplayColumn
   ' Move the selection to the end of the line.

   MsgBox("The length of the insertion point line is " & (objActive.DisplayColumn - iCol) & " display characters.")
End Sub