Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing ComboBox datasource in method

Status
Not open for further replies.

wallaceoc80

Programmer
Jul 7, 2004
182
GB
Hi everyone,

It's been a long while since I did vb.net and I can't remember how to do something very simple!!!

I have a ComboBox on form1 and another one on Form2. What I want to do is when the user clicks on a button that loads form2 I want to pass the DataSource from the ComboBox on form1 to the one on form2.

I assume this is possible but have a few questions:
1) Do I pass the paramater ByVal or ByRef?
2) Do I have the paramater on form2 as a type Object?
3) Is something like this enough?

Form1
Code:
Private Sub btnManage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnManage.Click
        Me.frmManageReports = New frmReportManage
        Me.frmManageReports.setupFromReport(Me.cmbReport.DataSource)
        Me.frmManageReports.Visible = True
End Sub

Form2
Code:
Public Sub setupFromReport(ByVal data As Object)
        Me.cmbFromReport.DataSource = data
        Me.cmbFromReport.Enabled = True
End Sub

Thanks for the help in advance.

Wallace
 
Code:
		Dim frm As New frmReportManage
		frm.cmbFromReport.DataSource = Me.cmbReport.DataSource
		frm.cmbFromReport.DisplayMember = Me.cmbReport.DisplayMember
		frm.cmbFromReport.ValueMember = Me.cmbReport.ValueMember
		frm.Show()

or you could pass the cmbReport.properties byval into a public method on the new form. DataSource is an Object, the other two are String values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top