Back to Devexpress

HeatmapControl.SelectedItemsChanged Event

windowsforms-devexpress-dot-xtracharts-dot-heatmap-dot-heatmapcontrol-62c3be63.md

latest6.4 KB
Original Source

HeatmapControl.SelectedItemsChanged Event

Occurs after the heatmap’s collection of selected items is changed.

Namespace : DevExpress.XtraCharts.Heatmap

Assembly : DevExpress.XtraCharts.v25.2.UI.dll

NuGet Package : DevExpress.Win.Charts

Declaration

csharp
public event SelectedItemsChangedEventHandler SelectedItemsChanged
vb
Public Event SelectedItemsChanged As SelectedItemsChangedEventHandler

Event Data

The SelectedItemsChanged event's data class is SelectedItemsChangedEventArgs. The following properties provide information specific to this event:

PropertyDescription
ActionGets an action which describes how the collection has been changed.
NewItemsProvides 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.
OldItemsProvides 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.

Remarks

The Heatmap Control stores selected cells in the HeatmapControl.SelectedItems collection. When a user clicks a cell, it (or the underlying data source object) is added to the collection and the SelectedItemsChanged event occurs. The SelectedItemsChanged event also occurs when a cell is deselected.

Example

The following example shows how to use heatmap selected cell data as a source for another chart:

Run Demo: Selection

csharp
public HeatmapSelection() {
    InitializeComponent();
    List<ProductSale> data = LoadData();
    HeatmapDataAdapter.DataSource = data;
    HeatmapDataAdapter.XArgumentComparer = new OriginalOrderComparer();
    heatmapControl1.SelectedItems.Add(data[0]);
}
List<ProductSale> LoadData() {
    List<ProductSale> data = new List<ProductSale>();
    try {
        XDocument sales_xml = XDocument.Load(Utils.GetRelativePath("ProductSales.xml"));
        foreach (XElement monthSale in sales_xml.Root.Elements()) {
            string product = monthSale.Element("Product").Value;
            string month = monthSale.Element("Month").Value;
            List<DailySale> dailySales = new List<DailySale>();
            foreach (XElement daySale in monthSale.Elements("SalesByDay").Elements("DailySale")) {
                dailySales.Add(new DailySale() {
                    Product = product,
                    Date = Convert.ToDateTime(daySale.Element("Date").Value),
                    Revenue = Convert.ToDouble(daySale.Element("Revenue").Value)
                });
            }
            data.Add(new ProductSale() { SalesByDay = dailySales });
        }
    }
    catch {
    }
    return data;
}
void heatmapControl1_SelectedItemsChanged(object sender, XtraCharts.SelectedItemsChangedEventArgs e) {
    List<DailySale> list = new List<DailySale>();
    foreach (ProductSale item in heatmapControl1.SelectedItems)
        list.AddRange(item.SalesByDay);
    chartControl1.DataSource = list;
}
vb
Public Sub New()
    Me.InitializeComponent()
    Dim data As System.Collections.Generic.List(Of DevExpress.XtraTreeMap.Demos.ProductSale) = Me.LoadData()
    Me.HeatmapDataAdapter.DataSource = data
    Me.HeatmapDataAdapter.XArgumentComparer = New DevExpress.XtraTreeMap.Demos.OriginalOrderComparer()
    Me.heatmapControl1.SelectedItems.Add(data(0))
End Sub
Private Function LoadData() As List(Of DevExpress.XtraTreeMap.Demos.ProductSale)
    Dim data As System.Collections.Generic.List(Of DevExpress.XtraTreeMap.Demos.ProductSale) = New System.Collections.Generic.List(Of DevExpress.XtraTreeMap.Demos.ProductSale)()
    Try
        Dim sales_xml As System.Xml.Linq.XDocument = System.Xml.Linq.XDocument.Load(DevExpress.XtraTreeMap.Demos.Utils.GetRelativePath("ProductSales.xml"))
        For Each monthSale As System.Xml.Linq.XElement In sales_xml.Root.Elements()
            Dim product As String = monthSale.Element(CType(("Product"), System.Xml.Linq.XName)).Value
            Dim month As String = monthSale.Element(CType(("Month"), System.Xml.Linq.XName)).Value
            Dim dailySales As System.Collections.Generic.List(Of DevExpress.XtraTreeMap.Demos.DailySale) = New System.Collections.Generic.List(Of DevExpress.XtraTreeMap.Demos.DailySale)()
            For Each daySale As System.Xml.Linq.XElement In monthSale.Elements("SalesByDay").Elements("DailySale")
                dailySales.Add(New DevExpress.XtraTreeMap.Demos.DailySale() With {.Product = product, .[Date] = System.Convert.ToDateTime(daySale.Element(CType(("Date"), System.Xml.Linq.XName)).Value), .Reve
            Next

            data.Add(New DevExpress.XtraTreeMap.Demos.ProductSale() With {.SalesByDay = dailySales})
        Next
    Catch
    End Try
    Return data
End Function

Private Sub heatmapControl1_SelectedItemsChanged(ByVal sender As Object, ByVal e As DevExpress.XtraCharts.SelectedItemsChangedEventArgs)
    Dim list As System.Collections.Generic.List(Of DevExpress.XtraTreeMap.Demos.DailySale) = New System.Collections.Generic.List(Of DevExpress.XtraTreeMap.Demos.DailySale)()
    For Each item As DevExpress.XtraTreeMap.Demos.ProductSale In Me.heatmapControl1.SelectedItems
        list.AddRange(item.SalesByDay)
    Next
    Me.chartControl1.DataSource = list
End Sub

See Also

HeatmapControl Class

HeatmapControl Members

DevExpress.XtraCharts.Heatmap Namespace