Newbie Question

C

cjobes

Hi all,

I'm still trying to understand the principle of a Windows Form Application.

I created the main form with a DataSet("Attendance") that has 2 tables.
After some processing I now want to show the results in a DataGrid on
another form that is called ResultForm. How can I create an incident of the
DataSet("Attendance") on the second form to be able to bind the DataGrid?

Thanks,

Claus
 
P

Phil Harvey

Hi Claus,
You could add a dataset property to the Result form, then set that property before displaying the form. When the property is set you could bind it to the ResultsForm datagrid. Below is some sample code that might be helpfull.

Public Class ResultsForm
Inherits System.Windows.Forms.Form

Private _results As DataSet

' Results DataSet property.
Public Property Results() As DataSet
Get
Return Me._results
End Get
Set(ByVal Value As DataSet)
Me._results = Value
' Bind property value to grid.
Me.ResultsGrid.DataSource = Me._results
End Set
End Property
End Class

' Create new ResultsForm, set the results property then display the form.
Public Sub ShowForm(ByVal results As DataSet)
Dim frmResults As New ResultsForm
frmResults.Results = results
frmResults.Show()
End Sub



Regards,
Phil Harvey
 
C

cjobes

Phil,

Thanks for the answer. When I implement your code the form does show but the grid is empty. I think my main problem is that I don't seem to understand how I can reference the DataSet from Form1 in the SearchResult form. When I work with just one form and display the DataGrid there, everything works fine.

Claus
Hi Claus,
You could add a dataset property to the Result form, then set that property before displaying the form. When the property is set you could bind it to the ResultsForm datagrid. Below is some sample code that might be helpfull.

Public Class ResultsForm
Inherits System.Windows.Forms.Form

Private _results As DataSet

' Results DataSet property.
Public Property Results() As DataSet
Get
Return Me._results
End Get
Set(ByVal Value As DataSet)
Me._results = Value
' Bind property value to grid.
Me.ResultsGrid.DataSource = Me._results
End Set
End Property
End Class

' Create new ResultsForm, set the results property then display the form.
Public Sub ShowForm(ByVal results As DataSet)
Dim frmResults As New ResultsForm
frmResults.Results = results
frmResults.Show()
End Sub



Regards,
Phil Harvey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top