-
Mar 5th, 2018, 03:27 PM
#1
Thread Starter
Fanatic Member
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
-
Mar 5th, 2018, 04:41 PM
#2
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 5th, 2018, 05:00 PM
#3
Thread Starter
Fanatic Member
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?
-
Mar 5th, 2018, 05:03 PM
#4
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...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 5th, 2018, 05:31 PM
#5
Thread Starter
Fanatic Member
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.
-
Mar 5th, 2018, 05:42 PM
#6
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...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 5th, 2018, 06:12 PM
#7
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|