Hi Darin,
Thank you for posting to Infragistics Community!
Most straightforward would be to handle the SelectedItemChanged event itself, i.e.:
private void PieChart_SelectedItemChanged(object sender, SelectedItemChangedEventArgs e )
{
var item = e.NewItem as DataItem;
if (item != null)
{
MessageBox.Show($"You clicked on: {item.Label} with value: {item.Value}");
}
}
If this must be done in the click event of the pie chart, though, a workaround might be needed. For example, I tested wrapping the selected item retrieval within a BeginInvoke action to execute it asynchronously on the same thread. Testing on my side proves that in this way the selection is retrieved after the click has been registered and the newly selected item has been assigned. Without the action, the selection would be persisted after the click handler has been executed. Please, find attached a small sample demonstrating this.
private void PieChart_Click(object sender, EventArgs e)
{
this.BeginInvoke(new Action(() =>
{
var selectedItem = pieChart.SelectedItem as DataItem;
if (selectedItem != null)
{
MessageBox.Show($"You clicked on: {selectedItem.Label} with value: {selectedItem.Value}");
}
}));
}
In conclusion, ideally the first approach would be preferred. If going down the second route, please, make sure to fully test the implementation to ensure that everything would be working as expected.
Best regards,
Bozhidara Pachilova
Software Developer