locked
Changed event RRS feed

  • Question

  • Hello group and thanks to those who replay. I have what I hope is a simple qestion.

     

    I have a windows form that is editing data contained in a dataset.  What I would like to do is capture an event on the form that will tell that the user has changed the current dataset row.  So if the user changes the row I would like to set a column in the data tabe to true to show that it was updated.

     

    Thanks

     

    Fred

     

    Sunday, September 28, 2008 1:42 PM

Answers

  • Hi 123fred

     

    Sorry for delay response. Here is my example.

    Code Snippet

    For i As Integer = 0 To dsCustomer.Tables("Customer").Rows.Count - 1

                If dsCustomer.Tables("Customer").Rows(i).RowState = DataRowState.Modified Then

                    Console.WriteLine("This row is Modified")

                End If

            Next

     

     

     

    Don’t hesitate to tell me if you have any more question.

     

    Sincerely,

    Kira Qian

     

    Windows Forms General FAQs
    Windows Forms Data Controls and Databinding FAQs

    Monday, October 6, 2008 1:46 AM

All replies

  • Code Snippet

     

    Private Sub MyDataTable_ColumnChanged(ByVal sender As Object,ByVal e As          

               System.Data.DataColumnChangeEventArgs) Handles MyDataTable.ColumnChanged

         If e.Column.ColumnName = "Col1" Then
            'do something here.

         End If
    End Su

     

     

     

     

    You can do the same thing with the rowChanged event.

     

     

    Hope this helps...
    Monday, September 29, 2008 8:55 PM
  • Hi

     

    You can handle the RowChanging event of a DataTable(DataSet.Table[index].RowChanging) to set the column value.

     

    Actually if you just want to make a marker at these changed rows to update them to the database, I don’t think you need to do this. Each row has a RowState which can tell you if the row is added or modified. You can use DataTable.Rows[index].RowState to get the row status.

     

    Sincerely,

    Kira Qian

     

    Windows Forms General FAQs
    Windows Forms Data Controls and Databinding FAQs

    Tuesday, September 30, 2008 6:48 AM
  •  

    Code Snippet

    Partial Class CustomerDataSet

    Partial Class CustomerDataTable

    Private Sub CheckFullName(ByVal customerRow As CustomerDataSet.CustomerRow)

    If customerRow.IsFullNameNull OrElse customerRow.FullName = "" Then

    customerRow.SetColumnError("FullName", "Please enter a full name.")

    Else

    customerRow.SetColumnError("FullName", "")

    End If

    End Sub

    Private Sub CustomerDataTable_ColumnChanged(ByVal sender As Object, ByVal e As System.Data.DataColumnChangeEventArgs) Handles Me.ColumnChanged

    'MsgBox("inside CustomerDataTable_ColumnChanged")

    ' Dim CustomerRow As CustDelvDataSet.CustomerRow

    ' CustomerRow = CType(e.Row, CustomerDataSet.CustomerRow) error cant convert

    ' CustomerRow.QBUpdate = True

    If e.Column Is Me.FullNameColumn Then

    Me.CheckFullName(e.Row)

    End If

    End Sub

    Private Sub CustomerDataTable_CustomerRowChanged(ByVal sender As Object, ByVal args As CustomerRowChangeEvent) Handles Me.CustomerRowChanged

    ' e.Row.QBUpdate = True

    'MsgBox("inside CustomerDataTable_CustomerRowChanged")

    'If args.Action <> DataRowAction.Nothing Then this works

    ' Dim actionStr As String

    ' actionStr = System.Enum.GetName(args.Action.GetType(), args.Action)

    ' Console.WriteLine(" RowChanged: Action = " & actionStr & ", FullName = " & args.Row("FullName").ToString())

    'End If

    End Sub

    Private Sub CustomerDataTable_RowChanged(ByVal sender As Object, ByVal e As System.Data.DataRowChangeEventArgs) Handles Me.RowChanged

    MsgBox("inside CustomerDataTable_RowChanged")

    End Sub

    Private Sub CustomerDataTable_TableNewRow(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs) Handles Me.TableNewRow

    Me.CheckFullName(CType(e.Row, CustomerDataSet.CustomerRow))

    End Sub

    End Class

    End Class

     

    I'm still trying to figure my problem out.  What I would like to do is set column QBUpdate to true when the user has changed any part of the data row when the user is on a particular editing form I have designed.   

     

    Questions

    1) "Sub CustomerDataTable_CustomerRowChanged" and "Sub CustomerDataTable_RowChanged" looks like they both handle the same thing. Is there a difference the subs get executed?

     

    2) Looks like the subs are executed when the dataset is being filled.  Is there a way to test what the current active form name (what would be my editing form) is inside the sub.

     

    Thanks for the replies

    Fred

    Thursday, October 2, 2008 12:44 AM
  • Kira,

     

    I'm trying to use your suggestion and I can't get the references to the rowsate correctly.

    You said to use datatable.Rows[index].rowstate - Do you have a sample to show?

     

    For i = 0 To Me.CustomerDataSet.Customer.Rows.Count - 1

    Console.WriteLine(me.CustomerDataSet.Customer.rowsIdea.????   )

    Next

     

    I want to loop thru all rows of the customer table in the dataset and for any row that have been modified set a column on that row to be true.  

     

    thanks

     

    Fred

    Sunday, October 5, 2008 11:14 PM
  • Hi 123fred

     

    Sorry for delay response. Here is my example.

    Code Snippet

    For i As Integer = 0 To dsCustomer.Tables("Customer").Rows.Count - 1

                If dsCustomer.Tables("Customer").Rows(i).RowState = DataRowState.Modified Then

                    Console.WriteLine("This row is Modified")

                End If

            Next

     

     

     

    Don’t hesitate to tell me if you have any more question.

     

    Sincerely,

    Kira Qian

     

    Windows Forms General FAQs
    Windows Forms Data Controls and Databinding FAQs

    Monday, October 6, 2008 1:46 AM