Databinding display record details form

kelmkone

Member
Joined
Jun 7, 2007
Messages
6
Programming Experience
1-3
Hi, I’m trying to bind controls on multiple forms. I have a datagrid on the main form which I’ve set to read only and a separate dialog form to perform the editing of a selected record. the problem however is that I don't know how to point to the record selected from the datagrid and display that record on the form. I can get it to display the first record in that table but don't know how to move it on to the selected other records in the datagrid. I have found an example in the Microsoft ADO.NET book which I’ve worked thought but it misses out some of the code. The section they show is below which uses an editdetail method to binds the textboxes to the datagrid, they also mention that this is called from a button event which creates an instance of the form and then calls the method (below) on the form. I was just wondering if anyone had any ideas:
Thanks!

VB.NET:
dim drvdetail as datarowview
dim vuedetail as dataview

Public Sub editdetails(ByVal cm As CurrencyManager)

        Dim dlgnew As New addnewenrollment
        drvdetail = CType(Me.cmorder.Current, DataRowView)
        vuedetail = drvdetail.DataView

        Me.BindingContext(vuedetail).Position = Me.cmorder.Position


        dlgnew.TextBox1.DataBindings.Add("text", vuedetail, "Enrolment_ID")
        dlgnew.TextBox2.DataBindings.Add("text", vuedetail, "Client_No*")
        dlgnew.TextBox3.DataBindings.Add("text", vuedetail, "Course_ID")
        dlgnew.TextBox4.DataBindings.Add("text", vuedetail, "Date_Enrolled")
        dlgnew.TextBox5.DataBindings.Add("text", vuedetail, "Date_Canceled")
        dlgnew.TextBox6.DataBindings.Add("text", vuedetail, "Achived")
        dlgnew.TextBox7.DataBindings.Add("text", vuedetail, "Client_Status")

        if me.showdialog = dialogresult.ok then
            cm.endcurrentEdit()
        else
            cm.cancelcurrentedit()
        end if
    End Sub
thanks
 
Last edited by a moderator:
databinding

Thanks for that, but still having trouble with the project. I’m not sure how to pass the currency manager to the sub. I’ve got two data bound sources on my main form both with a currency manager associated with each one:

cmclient = CType(BindingContext(dsclient, "tblclient"), CurrencyManager)
cmorder = CType(BindingContext(dsclient, "tblenrollment"), CurrencyManager)

I think that’s how you do it?

The dataset dsclient.tblclient is bound to textbox controls and the dataset dsclient.tblenrollment is bound to a datagrid on the main form. the dsclient.tblclient works fine on the form and moves along a record at a time via left and right arrow buttons, but it's the latter I’m having problems with ideally I would like the user to select a row in the datagrid then when the user clicks on edit that row is displayed in the separate dialog form. If anyone has any ideas I would be grateful, thanks
 
I would like the user to select a row in the datagrid then when the user clicks on edit that row is displayed in the separate dialog form

The way I did this in the end was to pass over the ID as a parameter to the 2nd form, and then reload the data on this form for that ID.
 
not a bad idea, does that mean that you made the user enter the record number first, pass the number over to the sub procedure and then refilled the dataset?
 
Youre using .NET 3.0
Its extremely rare, if ever, that you should be writing the words DataBindings, CurrencyManager or BindingContext in code.. THis implies youre following some old tutorial targeted at 1.1 or something..
 
Back
Top