Question

I have an Xceed datagrid in my WPF application and each cell is given an OnClick event. However, I would like to be able to handle that event depending on if the cell is the column header or if the cell is just storing data. If anyone has any advice or experience in this I would be more than grateful.

Was it helpful?

Solution

<Window.Resources>
<Style TargetType="xcdg:DataCell">
    <EventSetter Event="PreviewMouseLeftButtonDown" Handler="dataCellMouseLeftButtonDown"/>
</Style>
<Style TargetType="xcdg:ColumnManagerCell">
    <EventSetter Event="PreviewMouseLeftButtonDown" Handler="colManagerMouseLeftButtonDown"/>
</Style>
</Window.Resources>

<xcdg:DataGridControl ItemsSource="{Binding}"/>


 private void dataCellMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
    MessageBox.Show("Left mouse button down on Cell");
 }

 private void colManagerMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
   MessageBox.Show("Left mouse button down on Column manager cell");
 }

Note If you replace the preview-events with the normal events, then the events will not be triggered by the datagrid. It will handle these mouse events itself (start inline edit and sorting resp.).

OTHER TIPS

How do you set the event? You can target the datagridrow,datacell, columnheader cells with different styles and events. However you have to pay attention to the fact that several events are handled by the Xceed controls and you sometimes have to use the preview versions of the events.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top