• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

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!!!
0
tboy6423
Asked:
tboy6423
  • 3
  • 2
  • 2
  • +1
1 Solution
 
MrBookinsCommented:
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.
0
 
CyberLexCommented:
MainForm.txtCoNameBill.Text = Me.ComboBox1.text

cheers
Lex
0
 
JackOfPHCommented:
MainForm.txtCoNameBill.Text = Me.ComboBox1.SelectedText
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
tboy6423Author Commented:
Thank you all for your suggestions, but I have tried those...
0
 
MrBookinsCommented:
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.
0
 
tboy6423Author Commented:
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...
0
 
JackOfPHCommented:
Did you try setting the modifier of the txtCoNameBill textbox property to Public?
0
 
tboy6423Author Commented:
Everyone thank you for your help but I resolved it on my own....

On the serach form(form 2, that opens from the Main Form):

 Public Function GetSelection() As String
        Me.ShowDialog()
        Return Me.ComboBox1.SelectedValue()

On the main form:

 Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Dim SearchForm As New BillToLookupForm
        txtCoNameBill.Text = SearchForm.GetSelection

So when  the Search form is closed after the selection is made from the combobox it automatically populates the main form with the information selected.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now