locked
set datagrid current record to inserted record RRS feed

  • Question

  • i have a master detail page with a datagrid and dataform. There is a text box which users can enter a client reference number. If th reference bumber is not found, a child window pops uo with d ataform for insert. What I want to do is when a new record is inserted, and the child window is closed, the current record in the datagris should be set to the inserted record.. how is this possible

        Private Sub addNewClient_Closed(sender As Object, e As EventArgs)
            Dim Clients As cwClientAdminAdd = sender
            Dim dd As DomainDataSource = Ria_ClientSelection
    
            If Not Clients.NewtbCBI_client Is Nothing Then
                dd.DataView.Add(Clients.NewtbCBI_client)
                dd.SubmitChanges()
            Else
                dd.CancelSubmit()
            End If
        End Sub
    
        Private Sub Ria_ClientSelection_SubmittedChanges(sender As Object, e As System.Windows.Controls.SubmittedChangesEventArgs)
            If e.HasError Then
                MessageBox.Show(e.[Error].ToString(), "Submit Error", MessageBoxButton.OK)
                e.MarkErrorAsHandled()
            Else
                Me.DGClientSearch.ItemsSource = Nothing
                Me.DGClientSearch.ItemsSource = "{Binding ElementName=Ria_ClientSelection, Path=Data, Mode=OneWay}"
                Me.txtLicence.Text = ""
            End If
        End Sub
    
        Private Sub Ria_ClientSelection_LoadedData(sender As Object, e As System.Windows.Controls.LoadedDataEventArgs) Handles Ria_ClientSelection.LoadedData
            If Len(Me.txtLicence.Text) = 6 Then
                If e.TotalEntityCount = 0 Then
                    AddNewLicence(Me.txtLicence.Text)
                End If
            End If
        End Sub
    
        Private Sub AddNewLicence(Licence As String)
            Dim addNewClient As New cwClientAdminAdd(Licence)
            AddHandler addNewClient.Closed, AddressOf addNewClient_Closed
            addNewClient.Show()
    
        End Sub
    
    Sunday, July 31, 2011 12:19 AM

Answers

  • Normally you can pass the inserted record in addNewClient_Closed as an Event Argument. Then, you can set the DataGrid.SelectedItem property to the value of the inserted record instance.

    Sunday, July 31, 2011 5:20 PM
  • Hi,

    You can set the DataGrid.SelectedItem to your inserted item. You can store the reference of that item and find it back when the data loaded.

    Monday, August 1, 2011 10:48 PM

All replies

  • Normally you can pass the inserted record in addNewClient_Closed as an Event Argument. Then, you can set the DataGrid.SelectedItem property to the value of the inserted record instance.

    Sunday, July 31, 2011 5:20 PM
  • Hi,

    You can set the DataGrid.SelectedItem to your inserted item. You can store the reference of that item and find it back when the data loaded.

    Monday, August 1, 2011 10:48 PM