Back to Devexpress

Selection Modes

aspnet-9075-components-grid-view-concepts-aspxgridlookup-selection-modes.md

latest4.6 KB
Original Source

Selection Modes

  • May 07, 2023
  • 3 minutes to read

The ASPxGridLookup has a data-processing feature adopted from the ASPxGridView that allows users to select multiple list items within a drop-down grid.
Specify the ASPxGridLookup.SelectionMode property to configure the selection behavior:

  • Single - Only one item can be selected within the editor.
  • Multiple - Multiple items can be selected within the editor.

Note

  • The values contained in the key field (ASPxGridLookup.KeyFieldName) must be unique.
  • The SelectionMode property set to Multiple has no effect if the ASPxGridViewBehaviorSettings.AllowSelectSingleRowOnly property is set to true.
  • In single-selection mode, the GridLookup displays the focused row’s value in the edit box when a user sorts grid columns, navigates through pages, and so on. To restore the selected row’s value in the edit box, press Esc.

End User Item Selection

Users can select items in the following ways:

  • By clicking items within a dropdown grid.

  • By clicking item check boxes within the dropdown grid.

  • By entering tags into the editor’s edit box.

How to Access the Selected Items Programmatically

ASPxGridView behavior varies based on the specified mode.

If the SelectionMode property is set to Single, you should utilize a focused row instead of a selected row. In this case, use the ASPxGridLookup.Value property on the server side and the GetValue / SetValue methods on the client side to get/set the focused row.

If the SelectionMode property is set to Multiple, you can use the following child ASPxGridView control members to access the selected items:

See the following Support Center example to learn more: How to use ASPxGridLookup in multiple selection mode as the ASPxGridView editor.

Note

In Multiple selection mode, incremental filtering is disabled.

Example

The code sample below demonstrates how you can preselect some items in the ASPxGridLookup control by assigning the text of selected values to the ASPxGridLookup.Text property. Note that you should assign it according to the text format that you set in the ASPxGridLookup.TextFormatString property. The text of multiple selected rows is joined in the input using a special separator specified by the ASPxGridLookup.MultiTextSeparator property.

The image below shows the result.

aspx
<dx:ASPxGridLookup ID="gLookup" runat="server" DataSourceID="AccessDataSource1" 
     KeyFieldName="ProductID" TextFormatString="{1}" MultiTextSeparator=", " 
     ondatabound="gLookup_DataBound" SelectionMode="Multiple">
     <Columns>
          <dx:GridViewCommandColumn ShowSelectCheckbox="True" />
          <dx:GridViewDataTextColumn FieldName="ProductID">
          </dx:GridViewDataTextColumn>
          <dx:GridViewDataTextColumn FieldName="ProductName">
          </dx:GridViewDataTextColumn>
     </Columns>
</dx:ASPxGridLookup>
csharp
protected void gLookup_DataBound(object sender, EventArgs e) {
     gLookup.Text = "Chai, Chang, Ikura";
}
vb
Protected Sub gLookup_DataBound(ByVal sender As Object, ByVal e As EventArgs)
     gLookup.Text = "Chai, Chang, Ikura"
End Sub

See Also

Code Central example E3981: How to use ASPxGridLookup in multiple selection mode as the ASPxGridView editor