DataSet + 2 forms = Hell

zeroGrav

Newcomer
Joined
Jan 1, 2003
Messages
8
Hello there

I have two forms in my project. Form A and Form B.

Form A has a dataset, correctly configured with a local database, which is modified by a DataGrid object

Form B _has_ to modify form A's dataset (to add a new row to its DataGrid object)

If I pass a reference to Form A's Dataset in Form B's method and I try to add a new Row to the only table in the dataset, when I run the program the form B doesn't even draw. It presents itself as an uninitialised, basic form and the program is hung.

I said ok, I can't do this, so I tried another way. I programmed FOrm B to store information about what is to be entered into Form A's dataset inside itself, so then I can call an accessor method while in Form A and update the dataset from Form A. Sounds perefect but it's not.

What happens is once Form B is initialised, Form A continues its task without wayting for the data to be ready. I believe internally VB .NET uses threads...

How can I update this DataSet accessible from form A only while inside Form B ?

Here's some code
Visual Basic:
   Private Sub addTask(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menu_add.Click
        Dim df As New DataForm1()
        df.Show()
'''' Form A should wait here for df to finish...
        Dim tsk As Task
        tsk = df.getTask()      ''' this fails badly because form B is not ready, therefore tsk is Nothing      
        If tsk Is Nothing Then
            MsgBox("tsk is nothing")
        End If
        Dim table As New Data.DataTable()

        Dim row As System.Data.DataRow = table.NewRow()
        If IsNothing(row) Then
            MsgBox("row is nothing")
        End If

        row(1) = tsk.taskName
        row(2) = tsk.startTime
        row(3) = tsk.endTime
        row(4) = tsk.active
        row(5) = tsk.recurrent

        'add row to dataSet
        table.Rows.Add(row)

    End Sub

[edit]Please use
Visual Basic:
 tags [/vb ] [/edit]
 
Last edited by a moderator:
Instead of using the Show method of df, use the ShowDialog
method. This shows the form modally, like a message box, and
the code after it will not be executed until the form is closed.

Visual Basic:
Dim df As New DataForm1()
df.ShowDialog()
 
Back
Top