windowsforms-devexpress-dot-xtracharts-dot-chartcontrol-1e79d8e7.md
Occurs after the selection of a chart item has been changed.
Namespace : DevExpress.XtraCharts
Assembly : DevExpress.XtraCharts.v25.2.UI.dll
NuGet Package : DevExpress.Win.Charts
public event SelectedItemsChangedEventHandler SelectedItemsChanged
Public Event SelectedItemsChanged As SelectedItemsChangedEventHandler
The SelectedItemsChanged event's data class is SelectedItemsChangedEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Action | Gets an action which describes how the collection has been changed. |
| NewItems | Provides access to a collection of new selected chart elements (series and series points) and business data objects if a Chart Control or a series is bound to a data source. |
| OldItems | Provides access to previously selected chart elements (series and series points) and business data objects if a Chart Control or a series is bound to a data source. |
Use the SelectedItemsChanged event to customize the chart control behavior when the chart items and/ or business data objects (when using data binding) are selected.
For instance, you can display only bar series which correspond to the selected pie segments, as shown below.
This example shows how to obtain currently selected series points and show them in another chart. To do this, the ChartControl.SelectedItemsChanged event should be used.
In this example, you can choose the selection behavior ( Single , Multiple or Extended ) from the Selection Mode combo box. When any country is selected in the pie chart, you can see the population dynamics for each country in the bar chart. To cancel pie segment selection, choose None in the Selection Mode combo box.
In addition, this example demonstrates how to colorize each bar series point in the pie specific color using the ChartControl.CustomDrawSeriesPoint event.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraCharts;
namespace ChartSelection {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
PaletteEntry[] paletteEntries;
private void Form1_Load(object sender, EventArgs e) {
// Specify selection mode for the Pie chart.
this.cbSelectionMode.Properties.Items.AddRange(Enum.GetValues(typeof(ElementSelectionMode)));
this.cbSelectionMode.SelectedIndex = 2;
pieChart.SeriesSelectionMode = SeriesSelectionMode.Point;
// Handle the SelectedItemsChanged event for the Pie chart.
pieChart.SelectedItemsChanged += pieChart_SelectedItemsChanged;
// Handle the CustomDrawSeriesPoint event for the Bar chart.
barChart.CustomDrawSeriesPoint += barChart_CustomDrawSeriesPoint;
// Get palette entries of the pie chart.
paletteEntries = pieChart.GetPaletteEntries(pieChart.Series[0].Points.Count);
}
private void cbSelectionMode_SelectedIndexChanged(object sender, EventArgs e) {
pieChart.SelectionMode = (ElementSelectionMode)this.cbSelectionMode.SelectedItem;
}
private void pieChart_SelectedItemsChanged(object sender, SelectedItemsChangedEventArgs e) {
barChart.Series[0].Points.Clear();
foreach (SeriesPoint piePoint in pieChart.SelectedItems) {
SeriesPoint barPoint = new SeriesPoint(piePoint.Argument, piePoint.Values[0]);
barPoint.Tag = pieChart.Series[0].Points.IndexOf(piePoint);
barChart.Series[0].Points.Add(barPoint);
}
}
private void barChart_CustomDrawSeriesPoint(object sender, CustomDrawSeriesPointEventArgs e) {
BarDrawOptions barOptions = e.SeriesDrawOptions as BarDrawOptions;
int colorIndex = (int)e.SeriesPoint.Tag;
barOptions.Color = paletteEntries[colorIndex].Color;
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
Namespace ChartSelection
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private paletteEntries() As PaletteEntry
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
' Specify selection mode for the Pie chart.
Me.cbSelectionMode.Properties.Items.AddRange(System.Enum.GetValues(GetType(ElementSelectionMode)))
Me.cbSelectionMode.SelectedIndex = 2
pieChart.SeriesSelectionMode = SeriesSelectionMode.Point
' Handle the SelectedItemsChanged event for the Pie chart.
AddHandler pieChart.SelectedItemsChanged, AddressOf pieChart_SelectedItemsChanged
' Handle the CustomDrawSeriesPoint event for the Bar chart.
AddHandler barChart.CustomDrawSeriesPoint, AddressOf barChart_CustomDrawSeriesPoint
' Get palette entries of the pie chart.
paletteEntries = pieChart.GetPaletteEntries(pieChart.Series(0).Points.Count)
End Sub
Private Sub cbSelectionMode_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cbSelectionMode.SelectedIndexChanged
pieChart.SelectionMode = CType(Me.cbSelectionMode.SelectedItem, ElementSelectionMode)
End Sub
Private Sub pieChart_SelectedItemsChanged(ByVal sender As Object, ByVal e As SelectedItemsChangedEventArgs)
barChart.Series(0).Points.Clear()
For Each piePoint As SeriesPoint In pieChart.SelectedItems
Dim barPoint As New SeriesPoint(piePoint.Argument, piePoint.Values(0))
barPoint.Tag = pieChart.Series(0).Points.IndexOf(piePoint)
barChart.Series(0).Points.Add(barPoint)
Next piePoint
End Sub
Private Sub barChart_CustomDrawSeriesPoint(ByVal sender As Object, ByVal e As CustomDrawSeriesPointEventArgs)
Dim barOptions As BarDrawOptions = TryCast(e.SeriesDrawOptions, BarDrawOptions)
Dim colorIndex As Integer = CInt((e.SeriesPoint.Tag))
barOptions.Color = paletteEntries(colorIndex).Color
End Sub
End Class
End Namespace
The following code snippets (auto-collected from DevExpress Examples) contain references to the SelectedItemsChanged event.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
winforms-dashboard-custom-items/CS/TutorialsCustomItems/CustomItems/FunnelItemControlProvider.cs#L25
chart.MouseDoubleClick += MouseDoubleClick;
chart.SelectedItemsChanged += ChartSelectedItemsChanged;
chart.SelectedItemsChanging += ChartSelectedItemsChanging;
chart.MouseDoubleClick += MouseDoubleClick;
chart.SelectedItemsChanged += ChartSelectedItemsChanged;
chart.SelectedItemsChanging += ChartSelectedItemsChanging;
winforms-dashboard-custom-items/VB/TutorialsCustomItems/CustomItems/FunnelItemControlProvider.vb#L31
AddHandler chart.MouseDoubleClick, AddressOf MouseDoubleClick
AddHandler chart.SelectedItemsChanged, AddressOf ChartSelectedItemsChanged
AddHandler chart.SelectedItemsChanging, AddressOf ChartSelectedItemsChanging
AddHandler chart.MouseDoubleClick, AddressOf MouseDoubleClick
AddHandler chart.SelectedItemsChanged, AddressOf ChartSelectedItemsChanged
AddHandler chart.SelectedItemsChanging, AddressOf ChartSelectedItemsChanging
See Also