Back to Devexpress

ItemsViewOptionsSelection.AllowContentSelection Property

windowsforms-devexpress-dot-xtragrid-dot-views-dot-items-dot-itemsviewoptionsselection.md

latest4.9 KB
Original Source

ItemsViewOptionsSelection.AllowContentSelection Property

Gets or sets whether users can select the contents of HTML tags.

Namespace : DevExpress.XtraGrid.Views.Items

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
[DefaultValue(DefaultBoolean.Default)]
[XtraSerializableProperty]
public DefaultBoolean AllowContentSelection { get; set; }
vb
<DefaultValue(DefaultBoolean.Default)>
<XtraSerializableProperty>
Public Property AllowContentSelection As DefaultBoolean

Property Value

TypeDefaultDescription
DefaultBooleanDefault

Specifies the initial value of the user-select CSS property for all HTML elements. The DefaultBoolean.True value sets this property to auto , the DefaultBoolean.False and DefaultBoolean.Default values set it to none.

|

Available values:

NameDescriptionReturn Value
True

The value is true.

|

0

| | False |

The value is false.

|

1

| | Default |

The value is specified by a global option or a higher-level object.

|

2

|

Property Paths

You can access this nested property as listed below:

Object TypePath to AllowContentSelection
ItemsView

.OptionsSelection .AllowContentSelection

|

Remarks

Enable the AllowContentSelection property to allow users to select text displayed by HTML templates. Note that as users drag the mouse pointer to select a portion of text, button captions, images, and other HTML elements along the way are also selected.

Note

Currently, users can select only one row at a time. Selection across multiple rows is not currently available.

The textual content of the selected region is stored in the SelectedText property. The code below copies this property’s value to the clipboard when a user presses Ctrl+C:

csharp
private void OnKeyDown(object sender, KeyEventArgs e) {
    ItemsView iView = sender as ItemsView;
    if (e.Control && e.KeyCode == Keys.C)
        Clipboard.SetText(iView.SelectedText);
}
vb
Private Sub OnKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
    Dim iView As ItemsView = TryCast(sender, ItemsView)
    If e.Control AndAlso e.KeyCode = Keys.C Then Clipboard.SetText(iView.SelectedText)
End Sub

When the selection changes, the SelectedTextChanged event occurs. Handle this event to inspect and modify the SelectedText property value. For instance, you can cleanse it from the contents of non-textual elements that were selected along with regular text.

csharp
private void OnSelectedTextChanged(object sender, EventArgs e) {
    ItemsView iView = sender as ItemsView;
    string updatedText = iView.SelectedText.Replace(" OK Cancel ", " ");
}
vb
Private Sub OnSelectedTextChanged(ByVal sender As Object, ByVal e As EventArgs)
    Dim iView As ItemsView = TryCast(sender, ItemsView)
    Dim updatedText As String = iView.SelectedText.Replace(" OK Cancel ", " ")
End Sub

You can also use the user-select CSS property to prevent unwanted HTML elements from being selected when the AllowContentSelection property is enabled.

html
<div class="button unselectable">Cancel</div>
css
.unselectable { user-select: none; }

If the AllowContentSelection property is set to DefaultBoolean.Default or DefaultBoolean.False, utilize the user-select CSS property to enable selection for individual elements.

css
.selectable { user-select: all; }
.selectableText { user-select: text; }

See Also

ItemsViewOptionsSelection Class

ItemsViewOptionsSelection Members

DevExpress.XtraGrid.Views.Items Namespace