none
WPF Save Datagrid to SQLite RRS feed

  • Question

  • Hi,

    I have a customize template for a datagrid to which I add a table via a datatable with this code:

    DG1.ItemsSource = dt.DefaultView
    The user can change the values in the cells of this datagrid and when he hits save, I want to get the values back into the SQLite after reverting some tags in cells back to initial text.

    How do I get changed datagrid to datatable for manipulation and saving cell by cell to SQLite?

    I tried this

    dt2 = CType(DG1.ItemsSource, DataView).ToTable

    but it seems this only gets the initial values from datagrid while ignoring changes from the user. What am I missing? I use a new datatable dt2 for this instead of dt, which is used for filling datagrid.

    regards,

    Pascal


    • Edited by ElPazzo Thursday, May 2, 2019 10:20 PM
    Thursday, May 2, 2019 10:18 PM

All replies

  • Hi  ElPazzo,

    >>but it seems this only gets the initial values from datagrid while ignoring changes from the user. What am I missing?  

    You should use the INotifyPropertyChanged Interface In WPF.

    INotifyPropertyChanged interface is used to notify the bound control/data source reflects the change in the data source/ bound control without requiring the binding to be reset(UpdateSourceTrigger=PropertyChanged and Mode=TwoWay.).

    You can implement the INotifyPropertyChanged in your viewmodel or class.

     class NotificationProcess : INotifyPropertyChanged
        {
            public event PropertyChangedEventHandler PropertyChanged;
    
            public void RaisePropertyChanged(string propertyName)
            {
                if (this.PropertyChanged != null)
                {
                    this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
                }
            }
        }

    After you get the datasource, you can save it to the SQLite.


    The following link for your reference.

    Explain INotifyPropertyChanged In WPF - MVVM



    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.

    Friday, May 3, 2019 5:47 AM
    Moderator
  • Hi Yong,

    I managed to convert the code to VB (although converters generated more errors than necessary):

    Public Class NotificationProcess
    	Implements INotifyPropertyChanged
    
    	Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
    
    	Private Sub NotifyPropertyChanged(ByVal info As String)
    		RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
    	End Sub
    End Class

    but now I'm quite lost.

    I checked on the net to find some help about the INotifyPropertyChanged but to no avail.

    There is plenty of reference for C#, I even found some examples for VB net but all these are too theoretical for me to understand them or for being able to get them to a working example. Unfortunately I have a problem with theory of any kind; I just cannot grab it... :( I'm also a very beginner in WPF, before I only coded in aspx (vb.net) web applications, and I'm not a full time programmer but have a completely different main job and only programm whenever I got some spare time in the evenings.

    My XAML part where the data is used looks like this:

            <DataGrid x:Name="DG1" Margin="10,124,10,10" ItemsSource="{Binding ItemsSource}" HorizontalContentAlignment="Stretch" AutoGenerateColumns="False" Grid.RowSpan="2" CanUserAddRows="False">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Id" Binding="{Binding id}" Width="Auto"></DataGridTextColumn>
                    <DataGridTemplateColumn Header="source_segment" Width="50*">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <local:RichTextBoxHelper x:Name="rtb" VerticalScrollBarVisibility="Auto" keytoken ="13" TextValue="{Binding source_segment}">
                                </local:RichTextBoxHelper>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                        <DataGridTemplateColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextWrapping" Value="Wrap" />
                            </Style>
                        </DataGridTemplateColumn.CellStyle>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn Header="target_segment" Width="50*">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <local:RichTextBoxHelper x:Name="rtb" VerticalScrollBarVisibility="Auto" keytoken ="11" TextValue="{Binding target_segment}">
                                </local:RichTextBoxHelper>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                        <DataGridTemplateColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextWrapping" Value="Wrap" />
                            </Style>
                        </DataGridTemplateColumn.CellStyle>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>
            </DataGrid>

    and I get the data from here:

    DG1.ItemsSource = dt.DefaultView

    The user can change the text in the grid and after clicking a button I now want to be able to get the changed data in order to edit it in code behind before saving it back to SQLite.

    How can I tell INotifyPropertyChanged to get the changed data?

    Right now, to me, INotifyPropertyChanged and the whole "overloaded" MVVM functions just look like very cryptic strings that make no sense as I cannot see what belongs where as they are just too much back and forth and jumping from one function to the next before you actually get what you really need. So I'm completely lost also because the examples I found do not really provide much real explanation what happens where but are more, now we need this and then we need this to get this.

    regards,

    Pascal


    • Edited by ElPazzo Wednesday, May 15, 2019 9:26 PM
    Wednesday, May 15, 2019 9:23 PM
  •  


    Hi    ElPazzo,

    >>The user can change the text in the grid and after clicking a button I now want to be able to get the changed data in order to edit it in code behind before saving it back to SQLite.

    How can I tell INotifyPropertyChanged to get the changed data?

    1: Define a class inherit INotifyPropertyChanged

    Public Class MyObjectA  Implements ComponentModel.INotifyPropertyChanged 
    

    2: Raise PropertyChanged Event 

             Private m_MyNullableDouble As Double?
    	Public Property MyNullableDouble As Double?
    		Get
    			Return m_MyNullableDouble
    		End Get
    		Set(value As Double?)
    
    			m_MyNullableDouble = value
    			RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(NameOf(MyNullableDouble)))
    		End Set
    	End Property

    3:  Binding Mode set TwoWay.

    <TextBox Style="{StaticResource TextErrorStyle}" Text="{Binding MyNullableDouble,
                            Mode=TwoWay, 
                            UpdateSourceTrigger=LostFocus}" Margin="0,42,424,343" />
    
    
    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, May 16, 2019 3:16 AM
    Moderator
  • Hi Yong,

    Thanks, but I still do not get it to work. The code behind does not seem to get updated.

    I tried several things and right now I have this:

    I tried with binding ItemsSource and target_segment

    Public Class NotificationProcess
    	Implements INotifyPropertyChanged
    
    	Private m_MyNullableDouble As DataTable
    	Public Property target_segment As DataTable
    		Get
    			Return m_MyNullableDouble
    		End Get
    		Set(value As DataTable)
    
    			m_MyNullableDouble = value
    			RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(NameOf(target_segment)))
    		End Set
    	End Property
    
    	Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
    
    	Private Sub NotifyPropertyChanged(ByVal info As String)
    		RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
    	End Sub
    End Class

    XAML:

            <DataGrid x:Name="DG1" Margin="10,124,10,10" ItemsSource="{Binding ItemsSource, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" HorizontalContentAlignment="Stretch" AutoGenerateColumns="False" Grid.RowSpan="2" CanUserAddRows="False">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Id" Binding="{Binding id}" Width="Auto"></DataGridTextColumn>
                    <DataGridTemplateColumn Header="source_segment" Width="50*">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <local:RichTextBoxHelper x:Name="rtb" VerticalScrollBarVisibility="Auto" keytoken ="13" TextValue="{Binding source_segment}">
                                </local:RichTextBoxHelper>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                        <DataGridTemplateColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextWrapping" Value="Wrap" />
                            </Style>
                        </DataGridTemplateColumn.CellStyle>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn Header="target_segment" Width="50*">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <local:RichTextBoxHelper x:Name="rtb" VerticalScrollBarVisibility="Auto" keytoken ="11" TextValue="{Binding target_segment, Mode=TwoWay, UpdateSourceTrigger=LostFocus}">
                                </local:RichTextBoxHelper>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                        <DataGridTemplateColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextWrapping" Value="Wrap" />
                            </Style>
                        </DataGridTemplateColumn.CellStyle>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>
            </DataGrid>

    and the code behind for the button that should show the changes to the table in UI via MessageBox:

    	Private Sub Btn_send_Click(sender As Object, e As RoutedEventArgs) Handles Btn_send.Click
    		If boo_rb3checked = True Then
    			queries()
    		Else
    			NotifyPropertyChanged("ItemsSource")
    			Dim dt2 As New DataTable
    			dt2 = CType(DG1.ItemsSource, DataView).ToTable
    
    			For Each row As DataRow In dt2.Rows
    				For Each column As DataColumn In dt2.Columns
    					MessageBox.Show(row(column))
    				Next
    			Next
    
    		End If
    	End Sub
    but as I said, I still get the results before the text in table was change via UI.

    Regards,

    Pascal

    Sunday, May 19, 2019 10:21 PM
  • Hi Yong,

    Thanks, but I still do not get it to work. The code behind does not seem to get updated.

    I tried several things and right now I have this:

    I tried with binding ItemsSource and target_segment

    Public Class NotificationProcess
    	Implements INotifyPropertyChanged
    
    	Private m_MyNullableDouble As DataTable
    	Public Property target_segment As DataTable
    		Get
    			Return m_MyNullableDouble
    		End Get
    		Set(value As DataTable)
    
    			m_MyNullableDouble = value
    			RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(NameOf(target_segment)))
    		End Set
    	End Property
    
    	Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
    
    	Private Sub NotifyPropertyChanged(ByVal info As String)
    		RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
    	End Sub
    End Class

    XAML:

            <DataGrid x:Name="DG1" Margin="10,124,10,10" ItemsSource="{Binding ItemsSource, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" HorizontalContentAlignment="Stretch" AutoGenerateColumns="False" Grid.RowSpan="2" CanUserAddRows="False">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Id" Binding="{Binding id}" Width="Auto"></DataGridTextColumn>
                    <DataGridTemplateColumn Header="source_segment" Width="50*">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <local:RichTextBoxHelper x:Name="rtb" VerticalScrollBarVisibility="Auto" keytoken ="13" TextValue="{Binding source_segment}">
                                </local:RichTextBoxHelper>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                        <DataGridTemplateColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextWrapping" Value="Wrap" />
                            </Style>
                        </DataGridTemplateColumn.CellStyle>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn Header="target_segment" Width="50*">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <local:RichTextBoxHelper x:Name="rtb" VerticalScrollBarVisibility="Auto" keytoken ="11" TextValue="{Binding target_segment, Mode=TwoWay, UpdateSourceTrigger=LostFocus}">
                                </local:RichTextBoxHelper>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                        <DataGridTemplateColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextWrapping" Value="Wrap" />
                            </Style>
                        </DataGridTemplateColumn.CellStyle>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>
            </DataGrid>

    and the code behind for the button that should show the changes to the table in UI via MessageBox:

    	Private Sub Btn_send_Click(sender As Object, e As RoutedEventArgs) Handles Btn_send.Click
    		If boo_rb3checked = True Then
    			queries()
    		Else
    			NotifyPropertyChanged("ItemsSource")
    			Dim dt2 As New DataTable
    			dt2 = CType(DG1.ItemsSource, DataView).ToTable
    
    			For Each row As DataRow In dt2.Rows
    				For Each column As DataColumn In dt2.Columns
    					MessageBox.Show(row(column))
    				Next
    			Next
    
    		End If
    	End Sub
    but as I said, I still get the results before the text in table was change via UI.

    Regards,

    Pascal


    Hi   ElPazzo,

    From your description, I found you have defined a DataTable Property. It will not update the DataTable Property because the DataTable class not implement the INotifyPropertyChanged Interface. 

    You may need to change your structure. For example: use the ObservableCollection and binding to the local:RichTextBoxHelper.

    Private jb2 As ObservableCollection(Of YourObject) = New ObservableCollection(Of Of YourObject)()

    Then, get the ObservableCollection and save it to 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.

    Monday, May 20, 2019 7:43 AM
    Moderator
  • Hi Yong,

    Up to now I still have problems getting my datatable to an Observableobject as for VB documentation is very scarce.

    But while reading more about this topic I increasingly get the feeling that there is a misunderstanding with the answers I get here and what I want to achieve. (I already had that feeling with Inotifypropertychanged readings) Or did I just find the wrong tutorials or examples?

    All examples I find talk about updating UI with changes done to the list/collection in code behind (adding or removing items) but that's not what I need. My list/collection in code behind does not get changed or generate any new rows or update them in any other way while the user sees the table by clicking on a button.

    The user changes the existing strings in a static table (maybe some logic to remove rows could be added at a later stage but it's not planned right now) but no new ones added. At the end, the user clicks a button and I just want the app to get the changes the user did in UI so that I can run logic on the new strings as they exist in UI to replace some terms on in code behind and then save these to SQLite.

    regards,

    Pascal

    Tuesday, May 21, 2019 10:40 PM
  •  
    Hi   ElPazzo,

    >> My list/collection in code behind does not get changed or generate any new rows or update them in any other way while the user sees the table by clicking on a button.

    Use the ObservableCollection can update the UI control when add or remove items. 

    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, May 23, 2019 5:55 AM
    Moderator
  • Hi Yong,

    But exactly that is the problem!!! The user cannot add or remove any items. The existing strings only get changed/replaced to a new version which I need to save to SQLite when user hits the save button.

    All tutorials I found only talk about adding or removing items but not about replacing existing ones and then saving/synching these changes.

    regards,

    Pascal


    • Edited by ElPazzo Sunday, May 26, 2019 8:06 PM
    Sunday, May 26, 2019 7:52 PM
  •  
    Hi  ElPazzo,  

    >>But exactly that is the problem!!! The user cannot add or remove any items. 

    How do you add or remove items?


    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.

    Monday, May 27, 2019 8:52 AM
    Moderator
  •  
    Hi  ElPazzo,  

    >>But exactly that is the problem!!! The user cannot add or remove any items. 

    How do you add or remove items?


    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.

    Sorry Yong,

    But do you even understand the basics of English?????

    I wrote many times that the user and nobody else do/can NOT remove or add any rows or anything else.

    NIET, NADA, MÉI MÉN ER…

    The user can ONLY replace existing strings in UI.

    NOT in code behind, ONLY in UI!!!!!

    regards,

    Pascal

    Monday, May 27, 2019 10:05 AM

  • Hi   ElPazzo,

    >>I wrote many times that the user and nobody else do/can NOT remove or add any rows or anything else.

    The user can ONLY replace existing strings in UI.

    You mean you needn't to remove or add any items, but only want to get the new data which user changed in the UI?

    As I suggested above, you can use the INotifyPropertyChanged and binding a collection to your controls. Use the TwoWay Mode, the changed in the UI will update the source. 

    But, you said, you have an issue: "Up to now I still have problems getting my datatable to an Observableobject as for VB documentation is very scarce."

    I think you can change your ways. For examples:

    1: You can use the code to convert your collection to datatable and save in in your SQLite.

    2: If you don't use the collection as datasource, you can traverse the data of the control and save it to the data table.

    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, May 28, 2019 1:47 AM
    Moderator
  • Hi Yong,

    You mean you needn't to remove or add any items, but only want to get the new data which user changed in the UI?

    Correct.

    As I suggested above, you can use the INotifyPropertyChanged and binding a collection to your controls. Use the TwoWay Mode, the changed in the UI will update the source.

    Ok.

    Problem is that I'm trying to use Observableobject but with that one I cannot even get my datagrid table filled for user to work on. :( As I said documentation is veeeeeeeeeeeeeeeery scarce for VB.NET.

    Up to now I got this far:

    ... Public oc As New ObservableCollection(Of Pair) ... Public Class Pair #Region "Properties" Private id As String Private source_segment As String Private target_segment As String #End Region Public Property URID() As String Get Return id End Get Set(ByVal value As String) id = value End Set End Property Public Property SOURCE() As String Get Return source_segment End Get Set(ByVal value As String) source_segment = value End Set End Property Public Property TARGET() As String Get Return target_segment End Get Set(ByVal value As String) target_segment = value End Set End Property End Class 'and then I populate the OC like this: ...

    Dim PAAR As New Pair PAAR = New Pair PAAR.URID = str_id.ToString PAAR.SOURCE = str_source.ToString PAAR.TARGET = str_target.ToString

    oc.Add(PAAR) ... 'but the gridview does not get filled. I don't know how or find any reference on how to correctly bind it. DG1.ItemsSource = oc.AsEnumerable ' with this one I get a list with the correct amount of rows but they are all empty (no string), except for a space


    What am I missing?

    Edit: Now I get these errors:

    System.Windows.Data Error: 40 : BindingExpression path Error 'id' property not found on 'object' ''Pair' (HashCode=49201274)'. BindingExpression:Path=id; DataItem='Pair' (HashCode=49201274); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
    'System.Windows.Data Error: 40 : BindingExpression path Error 'source_segment' property not found on 'object' ''Pair' (HashCode=49201274)'. BindingExpression:Path=source_segment; DataItem='Pair' (HashCode=49201274); target element is 'RichTextBoxHelper' (Name='rtb'); target property is 'TextValue' (type 'String')
    'System.Windows.Data Error: 40 : BindingExpression path Error 'target_segment' property not found on 'object' ''Pair' (HashCode=49201274)'. BindingExpression:Path=target_segment; DataItem='Pair' (HashCode=49201274); target element is 'RichTextBoxHelper' (Name='rtb'); target property is 'TextValue' (type 'String')

    regards,

    Pascal


    • Edited by ElPazzo Wednesday, May 29, 2019 10:23 PM
    Wednesday, May 29, 2019 9:38 PM
  • Hi Yong,

    You mean you needn't to remove or add any items, but only want to get the new data which user changed in the UI?

    Correct.

    As I suggested above, you can use the INotifyPropertyChanged and binding a collection to your controls. Use the TwoWay Mode, the changed in the UI will update the source.

    Ok.

    Problem is that I'm trying to use Observableobject but with that one I cannot even get my datagrid table filled for user to work on. :( As I said documentation is veeeeeeeeeeeeeeeery scarce for VB.NET.

    Up to now I got this far:

    ... Public oc As New ObservableCollection(Of Pair) ... Public Class Pair #Region "Properties" Private id As String Private source_segment As String Private target_segment As String #End Region Public Property URID() As String Get Return id End Get Set(ByVal value As String) id = value End Set End Property Public Property SOURCE() As String Get Return source_segment End Get Set(ByVal value As String) source_segment = value End Set End Property Public Property TARGET() As String Get Return target_segment End Get Set(ByVal value As String) target_segment = value End Set End Property End Class 'and then I populate the OC like this: ...

    Dim PAAR As New Pair PAAR = New Pair PAAR.URID = str_id.ToString PAAR.SOURCE = str_source.ToString PAAR.TARGET = str_target.ToString

    oc.Add(PAAR) ... 'but the gridview does not get filled. I don't know how or find any reference on how to correctly bind it. DG1.ItemsSource = oc.AsEnumerable ' with this one I get a list with the correct amount of rows but they are all empty (no string), except for a space


    What am I missing?

    Edit: Now I get these errors:

    System.Windows.Data Error: 40 : BindingExpression path Error 'id' property not found on 'object' ''Pair' (HashCode=49201274)'. BindingExpression:Path=id; DataItem='Pair' (HashCode=49201274); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
    'System.Windows.Data Error: 40 : BindingExpression path Error 'source_segment' property not found on 'object' ''Pair' (HashCode=49201274)'. BindingExpression:Path=source_segment; DataItem='Pair' (HashCode=49201274); target element is 'RichTextBoxHelper' (Name='rtb'); target property is 'TextValue' (type 'String')
    'System.Windows.Data Error: 40 : BindingExpression path Error 'target_segment' property not found on 'object' ''Pair' (HashCode=49201274)'. BindingExpression:Path=target_segment; DataItem='Pair' (HashCode=49201274); target element is 'RichTextBoxHelper' (Name='rtb'); target property is 'TextValue' (type 'String')

    regards,

    Pascal


    Hi   ElPazzo,

    >> 'but the gridview does not get filled. I don't know how or find any reference on how to correctly bind it.

    DG1.ItemsSource = oc.AsEnumerable ' with this one I get a list with the correct amount of rows but they are all empty (no string), except for a space


    I try it on my side. 

       <DataGrid x:Name="DG1" ItemsSource="{Binding}"
                AutoGenerateColumns="False" Margin="0,0,0,256"   >
                <DataGrid.Columns>
                    <DataGridTemplateColumn Header="URID" >
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                  <TextBox Text="{Binding URID}"  ></TextBox>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTextColumn Header="SOURCE" Binding="{Binding SOURCE}"  />
                    <DataGridTextColumn Header="TARGET" Binding="{Binding TARGET}"  />
                </DataGrid.Columns>
            </DataGrid> 
    
    Imports System.Collections.ObjectModel
    
    Public Class datagridtest2
    
    	Private jb2 As ObservableCollection(Of Pair) = New ObservableCollection(Of Pair)()
    
    
    	Public Sub New()
    		InitializeComponent()
    		jb2.Add(New Pair() With {
    			.URID = "111111",
    			.SOURCE = "Job1",
    			.TARGET = "nEW TGAE1"
    		})
    		jb2.Add(New Pair() With {
    			.URID = "222222",
    			.SOURCE = "Job2",
    			.TARGET = "nEW TGAE2"
    		})
    		DG1.DataContext = jb2
    	End Sub
    
    
    
    	Public Class Pair
    #Region "Properties"
    		Private id As String
    		Private source_segment As String
    		Private target_segment As String
    #End Region
    
    		Public Property URID() As String
    			Get
    				Return id
    			End Get
    			Set(ByVal value As String)
    				id = value
    			End Set
    		End Property
    
    		Public Property SOURCE() As String
    			Get
    				Return source_segment
    			End Get
    			Set(ByVal value As String)
    				source_segment = value
    			End Set
    		End Property
    
    		Public Property TARGET() As String
    			Get
    				Return target_segment
    			End Get
    			Set(ByVal value As String)
    				target_segment = value
    			End Set
    		End Property
    	End Class
    
    End Class
    


    Note: Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.



    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, May 30, 2019 5:58 AM
    Moderator
  • Hi Yong,

    Still not working.

    Maybe it has to do with the fact that you used only textboxes in XAML but mine are set as Richtextboxes (see also error I  posted yesterday) set in Template. There is no way to remove the RTB as I need it for further formatting of the text.

    error:

    System.Windows.Data Error: 40 : BindingExpression path error: 'source_segment' property not found on 'object' ''Pairs' (HashCode=40158284)'. BindingExpression:Path=source_segment; DataItem='Pairs' (HashCode=40158284); target element is 'RichTextBoxHelper' (Name='rtb'); target property is 'TextValue' (type 'String')
    System.Windows.Data Error: 40 : BindingExpression path error: 'target_segment' property not found on 'object' ''Pairs' (HashCode=40158284)'. BindingExpression:Path=target_segment; DataItem='Pairs' (HashCode=40158284); target element is 'RichTextBoxHelper' (Name='rtb'); target property is 'TextValue' (type 'String')

    regards,

    Pascal

    Thursday, May 30, 2019 8:59 AM
  • Hi Yong,

    Still not working.

    Maybe it has to do with the fact that you used only textboxes in XAML but mine are set as Richtextboxes (see also error I  posted yesterday) set in Template. There is no way to remove the RTB as I need it for further formatting of the text.

    error:

    System.Windows.Data Error: 40 : BindingExpression path error: 'source_segment' property not found on 'object' ''Pairs' (HashCode=40158284)'. BindingExpression:Path=source_segment; DataItem='Pairs' (HashCode=40158284); target element is 'RichTextBoxHelper' (Name='rtb'); target property is 'TextValue' (type 'String')
    System.Windows.Data Error: 40 : BindingExpression path error: 'target_segment' property not found on 'object' ''Pairs' (HashCode=40158284)'. BindingExpression:Path=target_segment; DataItem='Pairs' (HashCode=40158284); target element is 'RichTextBoxHelper' (Name='rtb'); target property is 'TextValue' (type 'String')

    regards,

    Pascal

    Hi    ElPazzo,

    Please upload a minimal runnable demo to OneDrive(Including your test material and remove all private information). We can download it and debugging(reproduce your issue). This will help us quickly analyze your problem. 


    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.

    Friday, May 31, 2019 9:07 AM
    Moderator
  • Hi Yong,

    For security and privacy reasons, I'm not allowed to use onedrive or similar tools that do not only host within Europe but can send to any server in the world due to company policies.

    What I found that far is that observablecollection cannot bind to richtextbox like it does to any other controls. So I would need a workaround for this, then again there would be the problem: If I cannot bind directly in one direction, I cannot get the items back the other way round either.

    Or was there some new implementation of such feature within the last few months?

    regards,

    Pascal

    Monday, June 3, 2019 11:08 PM
  • Hi    ElPazzo,

    You can visit theDeveloper Community and suggest a feature.


    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, June 4, 2019 5:58 AM
    Moderator