Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. how to pass data from textbox in form1 to combobox in form2

how to pass data from textbox in form1 to combobox in form2

Scheduled Pinned Locked Moved C#
tutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    johnnysmith1
    wrote on last edited by
    #1

    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:
    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)
        {
    
        }
    }
    

    }

    this code allows me to enter data in textbox on first form and hit button and see it displayed on second form in label. is there a way to enter data in textbos on first form and hit button and see data entered into combobox on second form? thank you

    D 1 Reply Last reply
    0
    • J johnnysmith1

      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:
      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)
          {
      
          }
      }
      

      }

      this code allows me to enter data in textbox on first form and hit button and see it displayed on second form in label. is there a way to enter data in textbos on first form and hit button and see data entered into combobox on second form? thank you

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      Yes, using events. See this post[^] that I made a few days ago, as well as a working sample there is also a link to an article I wrote that explains events in much more detail if you want to gain a proper undestanding of the implementation but aimed at a beginner to events.

      Dave
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
      Why are you using VB6? Do you hate yourself? (Christian Graus)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups