IVsTextView.GetSelection Method (Int32, Int32, Int32, Int32)

 

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)

int GetSelection(
	out int piAnchorLine,
	out int piAnchorCol,
	out int piEndLine,
	out int piEndCol
)

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.

From textmgr.idl:

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

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

System_CAPS_noteNote

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.

Return to top
Show: