IVsTextView.GetSelection Method

Returns the text span corresponding to the current selection, if there is one.

Namespace:  Microsoft.VisualStudio.TextManager.Interop
Assembly:  Microsoft.VisualStudio.TextManager.Interop (in Microsoft.VisualStudio.TextManager.Interop.dll)

Syntax

'Declaration
Function GetSelection ( _
    <OutAttribute> ByRef piAnchorLine As Integer, _
    <OutAttribute> ByRef piAnchorCol As Integer, _
    <OutAttribute> ByRef piEndLine As Integer, _
    <OutAttribute> ByRef piEndCol As Integer _
) As Integer
int GetSelection(
    out int piAnchorLine,
    out int piAnchorCol,
    out int piEndLine,
    out int piEndCol
)
int GetSelection(
    [OutAttribute] int% piAnchorLine, 
    [OutAttribute] int% piAnchorCol, 
    [OutAttribute] int% piEndLine, 
    [OutAttribute] int% piEndCol
)
abstract GetSelection : 
        piAnchorLine:int byref * 
        piAnchorCol:int byref * 
        piEndLine:int byref * 
        piEndCol:int byref -> int
function GetSelection(
    piAnchorLine : int, 
    piAnchorCol : int, 
    piEndLine : int, 
    piEndCol : int
) : int

Parameters

  • piAnchorLine
    Type: System.Int32%

    [out] Anchor line position for the selection. Based on user selection, this value is not necessarily the upper line in the selection.

  • piAnchorCol
    Type: System.Int32%

    [out] Anchor column position for the selection. Based on user selection, this value is not necessarily the upper, left column position in the selection. Viewcol coordinates may include virtual space.

  • piEndLine
    Type: System.Int32%

    [out] End line position for the selection. Based on user selection, this value is not necessarily the lower line in the selection.

  • piEndCol
    Type: System.Int32%

    [out] End column position for the selection. Based on user selection, this value is not necessarily the lower, right column position in the selection. Viewcol coordinates may include virtual space.

Return Value

Type: System.Int32
If the method succeeds, it returns S_OK. If it fails, it returns an error code.

Remarks

COM Signature

From textmgr.idl:

HRESULT IVsTextView::GetSelection(
   [out] long *piAnchorLine,
   [out] ViewCol *piAnchorCol,
   [out] long *piEndLine,
   [out] ViewCol *piEndCol
);

The parameters for GetSelection can be nulla null reference (Nothing in Visual Basic) if they are not needed to determine the selection. To return this information in a TextSpan structure, call the GetSelectionSpan method.

Note

The anchor position is not always the left or upper position in the text view. For example, in a span of 10 lines, the user may anchor their selection in line 10 and end their selection in line 1, thus reversing the expected anchor/line order.

.NET Framework Security

See Also

Reference

IVsTextView Interface

Microsoft.VisualStudio.TextManager.Interop Namespace