I have a datagrid who’s ItemsSource is a strongly typed IEnumerable object
In this datagrid, I have a checkbox column, a price column, a part name column, and a ‘total selling for’ column.
On checking the checkbox I need to update the total selling for column with the value in the price column.
This part I have working, however, how can I get the checkbox to remain checked when this happens?
Private Sub UpdateSellFor(sender As System.Object, e As System.Windows.RoutedEventArgs)
Dim _CB As CheckBox = DirectCast(sender, CheckBox)
Dim _ID As Integer = _CB.Tag
Dim _PP = DirectCast(DG_PartsToSelect.CurrentItem, PartTyping).PartPrice
If _CB.IsChecked Then
DG_PartsToSelect.CurrentItem.PartSellingFor = DirectCast(DG_PartsToSelect.CurrentItem, PartTyping).PartPrice
DG_PartsToSelect.Items.Refresh()
Else
End If
'_CB.IsChecked = True
End Sub
uncommenting _CB.IsChecked = True does nothing
Here’s the XAML for this datagrid:
<DataGrid IsReadOnly="True" AutoGenerateColumns="False" Grid.Column="1" HorizontalAlignment="Stretch" Margin="3" Name="DG_PartsToSelect" VerticalAlignment="Stretch">
<DataGrid.Columns>
<DataGridTextColumn Header="Part ID" Binding="{Binding PartID}" />
<DataGridTemplateColumn Header="Part Name">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding PartName}" Cursor="Hand" MouseDown="PartDetails" Tag="{Binding PartID}" ToolTip="Click to See the Part Details" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Selling For" Binding="{Binding PartPrice, StringFormat='{}{0:C}'}" />
<DataGridTemplateColumn Header="Part Options">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Cursor="Hand" Height="22" Name="options" Tag="{Binding PartID}" MouseDown="PartOptions" Source="/v2Desktop;component/Images/Application.png" ToolTip="Select Part Options" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Sell This Part">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="SelectedPart" Tag="{Binding PartID}" ToolTip="Select This Part" Click="UpdateSellFor" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Total Selling For" Binding="{Binding PartSellingFor, StringFormat='{}{0:C}'}" />
</DataGrid.Columns>
</DataGrid>
Here is an example of how it is more the WPF way, hopefully this gets you in the right direction.
It has been a long time since I touched Visual Basic so please mind some missed conventions by me.
The Xaml:
Code Behind (Window Class and Part Class):