windowsforms-devexpress-dot-xtracharts-dot-chartcontrol-0c86e920.md
Occurs before any chart element is selected at runtime.
Namespace : DevExpress.XtraCharts
Assembly : DevExpress.XtraCharts.v25.2.UI.dll
NuGet Package : DevExpress.Win.Charts
public event HotTrackEventHandler ObjectSelected
Public Event ObjectSelected As HotTrackEventHandler
The ObjectSelected event's data class is HotTrackEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| AdditionalObject | Provides access to an object related to the object being hit. The returned value depends on the HotTrackEventArgs.Object type and hit point location. |
| Cancel | Gets or sets whether the hot-tracking should be cancelled. |
| HitInfo | Gets details on the chart elements located at the point where an end-user has clicked when hot-tracking or selecting a chart element at runtime. |
| Object | Gets the chart element, for which the event was raised. |
Users can select chart elements if the ChartControl.SelectionMode property is set to Single , Multiple or Extended. Handle the ObjectSelected event if you wish to perform specific actions when a user selects chart elements, or if you want to disable a selection of elements. You can use the the HotTrackEventArgs.Object property to access the selected element.
Note
If you handle the ObjectSelected event, it is raised regardless of the current ChartControl.SelectionMode property value.
This example demonstrates how to implement custom hot-tracking and selection of the chart’s elements at runtime.
Note
To enable runtime selection, the ChartControl.SelectionMode property should be set to Single , Multiple or Extended.
If you want to change the default hot-tracking and selection, you should handle the ChartControl.ObjectHotTracked and ChartControl.ObjectSelected events, implement your custom hot-tracking and selection approaches and set the Cancel property to true.
For example, the code below disables selection and hot-tracking of a chart’s diagram.
using DevExpress.XtraCharts;
// ...
private void chartControl1_ObjectHotTracked(object sender, HotTrackEventArgs e) {
// Prevent the chart's diagram from being hot-tracked.
if (e.Object is Diagram)
e.Cancel = true;
}
private void chartControl1_ObjectSelected(object sender, HotTrackEventArgs e) {
// Prevent the chart's Diagram from being selected.
if (e.Object is Diagram)
e.Cancel = true;
}
Imports DevExpress.XtraCharts
' ...
Private Sub OnObjectHotTracked(sender As Object, e As HotTrackEventArgs) _
Handles ChartControl1.ObjectHotTracked
' Prevent the chart's Diagram from being hot-tracked.
If TypeOf e.Object Is Diagram Then
e.Cancel = True
End If
End Sub
Private Sub OnObjectSelected(sender As Object, e As HotTrackEventArgs) _
Handles ChartControl1.ObjectSelected
' Prevent the chart's Diagram from being selected.
If TypeOf e.Object Is Diagram Then
e.Cancel = True
End If
End Sub
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ObjectSelected 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.
chart.ObjectHotTracked += Chart_ObjectHotTracked;
chart.ObjectSelected += Chart_ObjectSelected;
chart.MouseDoubleClick += MouseDoubleClick;
AddHandler chart.ObjectHotTracked, AddressOf Chart_ObjectHotTracked
AddHandler chart.ObjectSelected, AddressOf Chart_ObjectSelected
AddHandler chart.MouseDoubleClick, AddressOf MouseDoubleClick
See Also