Back to Devexpress

Highlight and Select Items

windowsforms-120630-controls-and-libraries-sunburst-control-highlight-and-select-items.md

latest6.4 KB
Original Source

Highlight and Select Items

  • Oct 29, 2020
  • 3 minutes to read

End users can highlight and select sunburst items. The Sunburst control provides an API that allows you to interact with the selected items in code.

Change the Highlight Mode

The SunburstControl.HighlightMode property specifies that elements are highlighted when the mouse pointer hovers over a sunburst item. The SunburstHighlightMode enumeration lists all the available modes:

|

Mode

|

Example

|

Description

| | --- | --- | --- | |

Single

|

|

The item is highlighted when the mouse pointer hovers over it.

| |

PathFromRoot (the default mode)

|

|

The item and all its parent items are highlighted when the mouse pointer hovers over it.

Use the SunburstControl.GetItemPath method to retrieve items that form the path from the top-level item to the specified item.

| |

WholeGroup

|

|

The item and its child items are highlighted when the mouse pointer hovers over it.

| |

None

|

|

Elements are not highlighted when they are hovered.

|

The code below shows how to specify the highlight mode:

csharp
sunburstControl.HighlightMode = SunburstHighlightMode.WholeGroup;
vb
sunburstControl.HighlightMode = SunburstHighlightMode.WholeGroup

Change the Selection Mode

The HierarchicalChartControlBase.SelectionMode property defines whether end users can select sunburst items. The ElementSelectionMode enumeration lists the available modes:

|

Mode

|

Example

|

Description

| | --- | --- | --- | |

Single

|

|

Only one element (item or group) can be selected.

| |

Multiple

|

|

Multiple items can be selected simultaneously.

| |

Extended

|

|

The Extended mode combines the Single and Multiple selection modes’ behaviors.

  • Click an item to select it.
  • To select/deselect multiple items, click them while the Ctrl or Shift key is pressed.

| |

None (the default mode)

| |

An end user cannot select sunburst items.

|

The code below shows how to specify the selection mode:

csharp
sunburstControl.SelectionMode = ElementSelectionMode.Single;
vb
sunburstControl.SelectionMode = ElementSelectionMode.Single

Interact with the Selected Items in Code

You can handle the HierarchicalChartControlBase.SelectionChanged event to track whether the selected Sunburst item collection changed.

The following code shows how to use the selected items as a chart’s and grid’s data source:

csharp
void OnSunburstSelectionChanged(object sender, SelectionChangedEventArgs e) {
    chartControl.DataSource = null;
    gridControl.DataSource = null;
    IList selectedItems = e.SelectedItems as IList;
    if (selectedItems != null && selectedItems.Count > 0) {
        chartControl.DataSource = selectedItems;
        gridControl.DataSource = selectedItems;
    }
}
vb
Private Sub OnSunburstSelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs) Handles sunburstControl.SelectionChanged
    chartControl.DataSource = Nothing
    gridControl.DataSource = Nothing
    Dim selectedItems As IList = TryCast(e.SelectedItems, IList)
    If selectedItems IsNot Nothing AndAlso selectedItems.Count > 0 Then
        chartControl.DataSource = selectedItems
        gridControl.DataSource = selectedItems
    End If
End Sub

The code above uses the following API members:

MemberDescription
HierarchicalChartControlBase.SelectionChangedOccurs after the selected sunburst items’ collection changes.
SelectionChangedEventArgsProvides data for the HierarchicalChartControlBase.SelectionChanged event.
SelectionChangedEventArgs.SelectedItemsReturns the selected items’ collection.

You can also use the HierarchicalChartControlBase.SelectedItems property to access the selected items’ collection.

If the Sunburst control is bound to data using its FlatDataAdapter or HierarchicalDataAdapter , the SelectedItems property returns the data source objects for the selected sunburst items. The SunburstItem.Tag property stores these data source objects.

If the Sunburst control uses ItemStorage , the SelectedItems property stores the selected sunburst items. Note that if the item’s Tag property is specified, the SelectedItems stores the Tag property values.