Current Record

bfafiani

Member
Joined
Mar 30, 2006
Messages
8
Programming Experience
1-3
Hi I would appreciate any help possible to this problem. I am new to .NET and ADO.NET so this might be a very simple problem.

I have a datagrid which displays Student records from a dataset 'DsStudents'21 The Datagrid is filtered however by each class group. I use a combo box for this. I need to edit/update these records in another form ("Update") using textboxes bound to the relivent columns in the dataset.

I want the user to select a row and click an "Edit" button to show the "Update" form with the textboxes populated with the current record.

So, How do I open the "Update" form with the textboxes filled with the currently selected row of the datagrid. Remembering that the datagrid does not show all the records in the table.

Here is the code I use to load the datagrid (except the call to LoadTable() )

PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
'Loads a list of unique ClassNames
DsCombo1.Clear()
OleDbDataAdapter2.Fill(DsCombo1)
EndSub

Sub LoadTable()
OleDbDataAdapter3.SelectCommand.Parameters("ClassName").Value = cmboClass.Text
'placing a value into the SQL parameter corresponding to the ClassName field
DsStudents21.Clear()
OleDbDataAdapter3.Fill(DsStudents21)
EndSub

-Thank You!-
 
Ok, create your form and add the textboxes that you want. Add the code in the click event of the edit button to show the form. Now i personally wouldn't use databinding here. I would put a property in the in the update form that holds a system.data.datarow, and private class level variable as the placeholder of the row you want to update.

Private MyRow as system.data.datarow

VB.NET:
Friend property RowToUpdate as system.data.datarow
Get 
Return MyRow
End Get
Set (byval Value as system.data.datarow)
myrow = value
End Set
End Property

Then before you show your update form. Pass the row you want to update to the property you just created.

VB.NET:
Dim MupdateForm as new updateform
mupdateform.rowtoupdate = 'the row to update'
mupdateform.showdialog
dim MyUpDatedRow as system.data.datarow = mupdateform.rowtoupdate
Then in the load event of the update form you can extract the info from the datarow using it's item property and populate the textboxes accordingly.
Then when your done repopulate the datarow with the new info. When your form closes you will have a datarow object in your original form with all the updated information. Repopulate the row in the datatable with this info. Job done.

And i just realised how long winded this was. But it is one way to do it.
 
Back
Top