none
Update Cell value on the dataGrid using MVVM wpf in VB.NET RRS feed

  • Question

  • Hello, I have an issues with the datagrid I ned to update the value of the cell when the FornViewModel change any data and click on the save button, on the DataGrid have to show automatic the new changes on the row selected, Now for see the new change I have to refresh the datagradview manually, close the application and show again the datagrid.

    so I need a help with this ticket as soon as possible.

    here I show an image what I need to do a graphic say better that 100 words

    Thanks any help will be great.

    Monday, August 12, 2019 7:12 PM

All replies

  • Hello, I have an issues with the datagrid I ned to update the value of the cell when the FornViewModel change any data and click on the save button, on the DataGrid have to show automatic the new changes on the row selected, Now for see the new change I have to refresh the datagradview manually, close the application and show again the datagrid.

    so I need a help with this ticket as soon as possible.

    here I show an image what I need to do a graphic say better that 100 words

    Thanks any help will be great.


    Hi    tomasorta,

    In WPF, you can  implement the INotifyPropertyChanged interface.

    INotifyPropertyChanged is an interface member in System.ComponentModel Namespace. This interface is used to notify the Control that the property value has changed.

    variable/property changed event in vb.net


    So, you can get the select item datasource(Object) and change the item in datacontext. Then, the Cell value on the dataGrid will update at the same time.


    Best regards

    Yong Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, August 13, 2019 3:05 AM
    Moderator
  • Thanks Yong Lu, I did follow the example for VB.net but the event just dispatch when populate the datagrid, after whern I open the view form to modify any data control, that I click close the view form, no any event dispatch from the data Model. I did this.

    ---- inmy class data model I have this--------------------

    Imports System.ComponentModel
    Namespace myapp.Models


    Public Class Employee
            Implements INotifyPropertyChanged
            Private _givenNameValue As String = String.Empty

            Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
            Private Sub NotifyPropertyChanged(ByVal propertyName As String)
                ' MsgBox(propertyName)
                ' Me.OnPropertyChanged(New PropertyChangedEventArgs(propertyName))
                RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
            End Sub
            Public Property PersonnelNum As Integer

            Public Property Surname As String
            Public Property GivenName As String
                Get
                    Return Me._givenNameValue
                End Get
                Set(ByVal value As String)
                    If Not (Me._givenNameValue = value) Then
                        Me._givenNameValue = value
                        'MsgBox(value)
                        NotifyPropertyChanged("GivenName")
                    End If
                End Set
            End Property

    end class

    end namespace

    ---------------------in the grid view  xaml---------------------------
    the coluimns have this

    <DataGridTextColumn x:Name="GivenNameColumn" Binding="{Binding GivenName,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                                <DataGridTextColumn.Header>
                                    <TextBlock Text="{Binding DataContext.LBLCGivenName, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" />
                                </DataGridTextColumn.Header>
                            </DataGridTextColumn>

    to dispatch the PropertyChanged when change anything on the grid.

    and in the Form View

       <TextBox 
                            materialDesign:HintAssist.Hint="{Binding LBLFirstName}" 
                            x:Name="GivenNameEmployee" 
                            Text="{Binding DataContext.GivenName, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,
      NotifyOnValidationError=true, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, ValidatesOnDataErrors=true, ValidatesOnExceptions=True}" 
                            
                            DataContext="{Binding}"
                            materialDesign:HintAssist.IsFloating="True"
                            materialDesign:HintAssist.FloatingOffset="5, -21"
                            Style="{StaticResource mys2}"
                            FontSize="12"                        
                            Width="295" Margin="0,96,0,45"
                            />

    on the button close on the Form View I have to update the database I didn't yet, my question now is I need to update the database for dispatch the event propertychanged on the property GivenName on the Data model?

    any Help will be great again!!!

    Tuesday, August 13, 2019 6:53 PM

  • Hi   tomasorta,

    >>my question now is I need to update the database for dispatch the event propertychanged on the property GivenName on the Data model?

    When you set the Mode=TwoWay,UpdateSourceTrigger=PropertyChanged, it will update the datasoure. But, it will not update your database. If you want to update the data in database, you need to detect the GivenName property set value event and update the corresponding data in the database.

    Best regards

    Yong Lu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 14, 2019 8:23 AM
    Moderator
  • Hi Young Lou, ok thanks you, I asked that because the datagrid never is update when I click on the button Close on the Form View, the property on the GivenName is trigers just when Load/realod the datagrid, after that is never trigers again, the example I found on internet and the you sent me is ok not errors, but no update the Cell data on that Row that I choose for Edit the data information, that is my goal to update all cell on that row where was change from FormView. I am working in MVVM,WPF with Prism 7.0 framework n VB.NET.

    thanks thomas

    Wednesday, August 14, 2019 12:07 PM
  • Hi Young Lou, ok thanks you, I asked that because the datagrid never is update when I click on the button Close on the Form View, the property on the GivenName is trigers just when Load/realod the datagrid, after that is never trigers again, the example I found on internet and the you sent me is ok not errors, but no update the Cell data on that Row that I choose for Edit the data information, that is my goal to update all cell on that row where was change from FormView. I am working in MVVM,WPF with Prism 7.0 framework n VB.NET.

    thanks thomas

    Hi    tomasorta,

    You may can  provide a minimal runnable demo(Including your test material and remove all private information and without Prism ) which could reproduce this issue.


    Best regards

    Yong Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, August 15, 2019 5:56 AM
    Moderator