Reputation: 51
iI'm working on a program which should change the checkbox state by clicking on it.
I used a "PreviewMouseLeftButtonUp" Event. The Problem is that, it doesn't get called when i press on an item. It only get called if i click on an empty place in the Datagrid.
Code:
Private Sub BefundePat1_PreviewMouseLeftButtonUp(sender As Object, e As MouseButtonEventArgs) Handles BefundePat1.PreviewMouseLeftButtonUp
Dim cell As DataGridCell = getGridCell(e.OriginalSource)
If Not cell Is Nothing Then
If BefundePat1.Columns(BefundePat1.Columns.Count - 1) Is cell.Column Then
If TypeOf cell.DataContext Is DataRowView Then
Dim dr As DataRowView = cell.DataContext
If dr.Row.Item("NR_TAKE") = True Then
dr.Row.Item("NR_TAKE") = False
Else
dr.Row.Item("NR_TAKE") = True
End If
End If
End If
End If
End Sub
Is it possible that it get distracted by the PreviewMouseLeftButtonDown Event i also have in the programm?
Kind Regards
Upvotes: 0
Views: 298
Reputation: 169200
I am not sure what you are trying to do here but tou could try to define a CellStyle
that raises the event for each DataGridCell
. Remove Handles BefundePat1.PreviewMouseLeftButtonUp
from your event handler and add the style in your XAML markup:
<DataGrid x:Name="BefundePat1" ...>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<EventSetter Event="PreviewMouseLeftButtonUp" Handler="BefundePat1_PreviewMouseLeftButtonUp" />
</Style>
</DataGrid.CellStyle>
...
</DataGrid>
If this doesn't work, you could try handling the PreviewMouseLeftButtonDown
event. Please clarify your requirements if you need any further help.
Upvotes: 1