dcsimg
Results 1 to 7 of 7

Thread: Appropriate Data input method

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    459

    Appropriate Data input method

    I have a form bound to a specific dataset table. I have just added a row to the table. The table is still open, as I have not applied the EndEdit() and Update() functions yet. There are a handful of hidden fields (columns if you will) that are not bound to any controls on the form and I want to input data into those fields using global variables that have already been assigned values.

    The code below is what I think is appropriate for inputting the values into the new row, but my question is whether that can be done if the row has not yet been updated? If that is the case, what method should I use for a newly added row?

    Code:
                CType(frmChangeRequest.tblChangeMasterBindingSource.Current, DataRowView).Item("chrFilePath") = glbstrFilePath
                CType(frmChangeRequest.tblChangeMasterBindingSource.Current, DataRowView).Item("chrBaseObject") = glbstrObject

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    21,833

    Re: Appropriate Data input method

    This works...

    Code:
    Public Class Form1
    
        Private WithEvents dt As New DataTable
    
        Dim glbValue As String = "glbValue"
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            dt.Columns.Add("First")
            dt.Columns.Add("Second")
            dt.Rows.Add("test", "test")
            DataGridView1.DataSource = dt
        End Sub
    
        Private Sub dt_TableNewRow(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs) Handles dt.TableNewRow
            e.Row.Item("Second") = glbValue
        End Sub
    
    End Class

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    459

    Re: Appropriate Data input method

    Thanks Paul.

    I was kind of thinking that the e.Row.Item() function might be what should be used instead, but I wasn't sure that it could be used outside of a datagridview. I am assuming from this that the method I used will not work if the row has not yet been updated?

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    21,833

    Re: Appropriate Data input method

    In a dgv, the field is inserted as soon as you click on the newrow. I'm not sure exactly how you can use it in your application, but it is the datatable event, rather than the datagridview event...

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    459

    Re: Appropriate Data input method

    I am really not clear about all of this. So here is what I did. All of this is taking place in a form class. Upstream in the code (in the Form_Load event I needed a new row in a table and had some, but not all, of the data that would be needed to populate that new row.

    At that point I added a row and populated it with the data that I had at that time. This was the method I used:

    Code:
                Dim ChangeRow As _MasterBase_1_0DataSet.tblChangeMasterRow
                ChangeRow = frmChangeRequest._MasterBase_1_0DataSet.tblChangeMaster.NewtblChangeMasterRow
                ChangeRow.intChangeID = glbintChangeID
                ChangeRow.intProcessID = glbintProcessID
                ChangeRow.chrRevision = glbstrRevision
                ChangeRow.chrBaseObject = glbstrObject
                frmChangeRequest._MasterBase_1_0DataSet.tblChangeMaster.Rows.Add(ChangeRow)
    The above method also happens to be the only method I know to add a new row.

    The value for the variable glbstrFilePath, (which is used to define the value in a specific column in this newly added row) cannot be assigned until the point I am done and ready to update the row. I know that I can add this to the row after the update, but I would prefer to do it prior to the update. I had thought that the method I had used might do that prior to an update, but was not sure.

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    21,833

    Re: Appropriate Data input method

    What code are you using for the update? If you declare ChangeRow at form or class level, you can change fields anywhere in your form or class code...

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    459

    Re: Appropriate Data input method

    I use the following:

    Code:
                tblChangeMasterBindingSource.EndEdit()
                TblChangeMasterTableAdapter.Update(frmChangeRequest._MasterBase_1_0DataSet)
    Again, because that is all I know.

    The ChangeRow is executed in the Form_Load event of the Form Class and the Update is execute in a button_Click event in the same Form Class.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width