Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7678713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:42:40+00:00 2026-05-31T17:42:40+00:00

I have a datagrid who’s ItemsSource is a strongly typed IEnumerable object In this

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:42:41+00:00Added an answer on May 31, 2026 at 5:42 pm

    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:

        <DataGrid AutoGenerateColumns="False" HorizontalAlignment="Stretch" Margin="3" x:Name="DG_PartsToSelect" VerticalAlignment="Stretch" ItemsSource="{Binding}">
          <DataGrid.Columns>
            <DataGridTextColumn Header="ID" Binding="{Binding Path=ID}" IsReadOnly="True" />
            <DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" IsReadOnly="True"/>
            <DataGridTemplateColumn Header="Selling For">
              <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                  <TextBlock Text="{Binding Path=SellingPrice, StringFormat='{}{0:C}', Mode=OneWay}"/>
                </DataTemplate>
              </DataGridTemplateColumn.CellTemplate>
              <DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                  <TextBox Text="{Binding Path=SellingPrice, UpdateSourceTrigger=PropertyChanged}"/>
                </DataTemplate>
              </DataGridTemplateColumn.CellEditingTemplate>
            </DataGridTemplateColumn>
            <DataGridTemplateColumn Header="Part Options">
              <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                  <Border Background="#88BBFF" Cursor="Hand" Height="22" ToolTip="Select Part Options" MouseUp="PartOptions_MouseUp"/><!--just for testing with no image-->
                  <!--<Image Cursor="Hand" Height="22" Source="" ToolTip="Select Part Options" MouseDown="PartOptions_MouseDown"/>-->
                </DataTemplate>
              </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
            <DataGridTemplateColumn Header="Sell This Part">
              <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                  <CheckBox Name="SelectedPart" IsChecked="{Binding Path=IsCalculated, UpdateSourceTrigger=PropertyChanged}" ToolTip="Select This Part"  />
                </DataTemplate>
              </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
            <DataGridTextColumn IsReadOnly="True" Header="Total Selling For" Binding="{Binding Path=TotalSellingFor, StringFormat='{}{0:C}'}" />
          </DataGrid.Columns>
        </DataGrid>
    

    Code Behind (Window Class and Part Class):

    Imports System.ComponentModel
    Imports System.Collections.ObjectModel
    
    Class MainWindow
    
      Dim Parts As ObservableCollection(Of Part)
    
      Private Sub PartOptions_MouseUp(sender As System.Object, e As System.Windows.Input.MouseButtonEventArgs)
        If DG_PartsToSelect.SelectedItem Is Nothing Then
          Exit Sub
        End If
        Dim selectedPart = DirectCast(DG_PartsToSelect.SelectedItem, Part)
        MessageBox.Show(String.Format("The name = {0}", selectedPart.Name), String.Format("The id = {0}", selectedPart.ID), MessageBoxButton.OK, MessageBoxImage.Information)
      End Sub
    
      Public Sub New()
        InitializeComponent()
        Parts = New ObservableCollection(Of Part)
        Parts.Add(New Part(1, "test", 100D))
        Parts.Add(New Part(2, "Name here", 99.99D))
        Parts.Add(New Part(3, "What", 23.19D))
        DG_PartsToSelect.DataContext = Parts
      End Sub
    End Class
    
    Public Class Part : Implements INotifyPropertyChanged
    
      Private IDField As Integer
      Public Property ID() As Integer
        Get
          Return IDField
        End Get
        Set(ByVal value As Integer)
          IDField = value
          OnPropertyChanged("ID")
        End Set
      End Property
    
      Private NameField As String
      Public Property Name() As String
        Get
          Return NameField
        End Get
        Set(ByVal value As String)
          NameField = value
          OnPropertyChanged("Name")
        End Set
      End Property
    
      Private SellingPriceField As Decimal
      Public Property SellingPrice() As Decimal
        Get
          Return SellingPriceField
        End Get
        Set(ByVal value As Decimal)
          SellingPriceField = value
          OnPropertyChanged("SellingPrice")
          IsCalculatedField = False
          OnPropertyChanged("IsCalculated")
        End Set
      End Property
    
      Private IsCalculatedField As Boolean
      Public Property IsCalculated() As Boolean
        Get
          Return IsCalculatedField
        End Get
        Set(ByVal value As Boolean)
          If (IsCalculatedField And Not value) Then
            Exit Property
          End If
          IsCalculatedField = value
          UpdateTotalPrice()
        End Set
      End Property
    
      Private TotalSellingForField As Decimal
      Public Property TotalSellingFor() As Decimal
        Get
          Return TotalSellingForField
        End Get
        Set(ByVal value As Decimal)
          TotalSellingForField = value
        End Set
      End Property
    
      Public Event PropertyChanged As PropertyChangedEventHandler _
            Implements INotifyPropertyChanged.PropertyChanged
    
      Public Sub New(id As Integer, name As String, sellingPrice As Decimal)
        IDField = id
        NameField = name
        SellingPriceField = sellingPrice
      End Sub
    
      Sub UpdateTotalPrice()
        ''This will multiply the price of the SellingPriceValue times 2 and put it in the TotalSellingForField
        TotalSellingForField = SellingPriceField * 2
        OnPropertyChanged("TotalSellingFor")
      End Sub
    
      Sub OnPropertyChanged(propertyName As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
      End Sub
    
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datagrid called DataGridView1, column A contains a name, column B contains
I have a DataGrid in WPF app with several columns, including a Name column.
I have a WPF application with a datagrid who's ItemsSource is a BindingList. When
I have Datagrid which is bound to my Database <WpfToolkit:DataGrid Name=DataGrid1 Grid.Row=1 ItemsSource={Binding Path=MainSearchBinding}
i am new to wpf, i have datagrid as follows, <DataGrid Grid.Row=0 x:Name=dg1 Grid.Column=0
I have a WPF DataGrid who's data source is an ObservableCollection. It is set
I have a dataGrid(not dataGridView) in which i need to add Checkbox dynamically at
I have a datagrid column with a button that opens a modal dialog box
I have a DataGrid who's RowDetails is set to show when selected (RowDetailsVisibilityMode=VisibleWhenSelected). Now
I have datagrid with list of MyPlayer objects linked to ItemsSource, there are ComboBoxes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.