Link to home
Start Free TrialLog in
Avatar of tboy6423
tboy6423Flag for United States of America

asked on

Passing the selected item in a combobox to a text field on another form..

In the app that I am creating using Visual Studios 2008, vb.net, I have a Main form and a sub form that opens to do a search. On that search form it has a combobox that pulls data from a dataset and populates the corresponding textboxes with data. What I am trying to do is pass that data on the search form to the Main form (to the appropriate textboxes) on a button click. Below is the code I am using:

Private Sub btnAddBillcompany_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddBillcompany.Click

        MainForm.txtCoNameBill.Text = Me.ComboBox1.SelectedItem.ToString

        Me.Hide()

    End Sub
When I run this I select the company name, and click the button, the window hides but the textbox on the main form is not populated with the selected text... Any help would be appreciated!!!
Avatar of MrBookins
MrBookins
Flag of United States of America image

If you add a breakpoint at " MainForm.txtCoNameBill.Text = Me.ComboBox1.SelectedItem.ToString" can you confirm that a value is actually being retrieved from the ComboBox?  Maybe print  Me.ComboBox1.SelectedItem.ToString to the debug console, and see what the output it.
MainForm.txtCoNameBill.Text = Me.ComboBox1.text

cheers
Lex
MainForm.txtCoNameBill.Text = Me.ComboBox1.SelectedText
Avatar of tboy6423

ASKER

Thank you all for your suggestions, but I have tried those...
If you add a breakpoint at " MainForm.txtCoNameBill.Text = Me.ComboBox1.SelectedItem.ToString" can you confirm that a value is actually being retrieved from the ComboBox?  I created code similar to yours and it worked fine.
Does it matter that I am using a dataset that populates that combobox? Also don't  I have to do something to the other form..the one that will be populated with the data? I added a breakpoint but no errors...
Did you try setting the modifier of the txtCoNameBill textbox property to Public?
ASKER CERTIFIED SOLUTION
Avatar of tboy6423
tboy6423
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial