+ Reply to Thread
Results 1 to 7 of 7

Thread: add data to textbox in form1 and add to combobox in form2

  1. #1
    Barn Regular arloguth is an unknown quantity at this point arloguth's Avatar
    Join Date
    Apr 2009
    Posts
    61
    Rep Power
    3

    add data to textbox in form1 and add to combobox in form2

    Hello,
    I have a textbox and button on form1.
    I have a label and combobox on form2.
    right now the code lets me enter data in textbox an click button to open form2 and have it displayed in label.
    But I cannot figure out how to add it to the combobox.
    I have tried combobox1.item.add(strTextBox) in form2 load - but not working
    thank you
    Code:
    namespace Passing_Data 
    { 
        public partial class Form1 : Form 
        { 
            public Form1() 
            { 
                InitializeComponent(); 
            } 
     
            private void button1_Click(object sender, EventArgs e) 
            { 
                Form2 frm = new Form2(textBox1.Text); 
                frm.Show(); 
     
            } 
     
            private void Form1_Load(object sender, EventArgs e) 
            { 
     
            } 
        } 
    }
    
    FORM 2:
    Code:
    namespace Passing_Data 
    { 
        public partial class Form2 : Form 
        { 
            public Form2(String strTextBox) 
            { 
                InitializeComponent(); 
                label1.Text = strTextBox; 
            } 
     
            private void Form2_Load(object sender, EventArgs e) 
            { 
     
            } 
     
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) 
            { 
     
            } 
        } 
    }
    
    Last edited by micky; January 18th, 2010 at 04:34 AM. Reason: Added code tags, please do so in future

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Is there a reason why you need 2 form elements on the page?

    Could you not just do it in one?

  3. #3
    Barn Regular arloguth is an unknown quantity at this point arloguth's Avatar
    Join Date
    Apr 2009
    Posts
    61
    Rep Power
    3

    Eventually what I am working towards is a form that connects to access database- users will enter data on form every week.
    the combobox or anytype of listbox- will have a list of names.
    after I create executable file- I want one of the users to still be able to add a name.
    I thought I would have an addEmployee Name under file menu - and form comes up and then they can add name
    thank you

  4. #4
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    OK. Then your listbox would then just be bound to the Access table that contains the names.

    So, when you add a name, it gets added to your Access table. Then when someone enters data, the listbox is populated with the values from the Access table.

    I presume we're talking about a Windows Forms application then?

  5. #5
    Barn Regular arloguth is an unknown quantity at this point arloguth's Avatar
    Join Date
    Apr 2009
    Posts
    61
    Rep Power
    3

    yes your correct

  6. #6
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I'm not sure I see what the issue is.

    In your "Add Name" form you retrieve the textbox values and add them to your Access table.

    In your other form you bind the DropDownList to a datasource that retrieves the names from the Access table.

    The two forms are unrelated. One adds data to the database, another has a dropdownlist that binds to data retrieved from the database.

  7. #7
    Barn Regular arloguth is an unknown quantity at this point arloguth's Avatar
    Join Date
    Apr 2009
    Posts
    61
    Rep Power
    3

    the way you just explained it clears things up for me - and makes me realize I can do things on seperate forms- thanks for patience and advice

+ Reply to Thread

Similar Threads

  1. selecting items from a combobox
    By yangski in forum .NET Development
    Replies: 1
    Last Post: August 5th, 2009, 09:16 PM
  2. textbox events
    By todd2006 in forum .NET Development
    Replies: 12
    Last Post: April 13th, 2009, 09:16 AM
  3. Replies: 5
    Last Post: June 25th, 2008, 09:07 AM
  4. populate combobox from another
    By Jaykappy in forum Microsoft Access
    Replies: 4
    Last Post: May 7th, 2008, 03:56 PM
  5. Textbox or List help
    By Rebelle in forum JavaScript Programming
    Replies: 9
    Last Post: April 21st, 2008, 11:00 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO