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
  1. Home
  2. General Programming
  3. C#
  4. substring from form1 to form2....

substring from form1 to form2....

Scheduled Pinned Locked Moved C#
comhelptutorialquestion
3 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.
  • G Offline
    G Offline
    Goaty65109
    wrote on last edited by
    #1

    Hey CP, Getting text from one form to another is no problem. But I am having issues showing data from a ComboBox from form1 to display as text in form 2. Alright let's jump right into my example.

    string instText = comboInst.GetItemText(comboInst.SelectedItem);
    string folder = instText.Substring(0, 4);

    comboInst is a combo box that has a list of items that is pulled from a directory. All items have a leading 4 digits that I use a lot in form1. But I can't get those 4 values for the life of me to show even in a messagebox on form 2. It just shows blank when using methods that pull information from a textBox.Text. I need to be able to use both instText and folder strings in other forms. Anyone got any ideas? The example I used is located on stackOverflow: [^] Thanks!

    J 1 Reply Last reply
    0
    • G Goaty65109

      Hey CP, Getting text from one form to another is no problem. But I am having issues showing data from a ComboBox from form1 to display as text in form 2. Alright let's jump right into my example.

      string instText = comboInst.GetItemText(comboInst.SelectedItem);
      string folder = instText.Substring(0, 4);

      comboInst is a combo box that has a list of items that is pulled from a directory. All items have a leading 4 digits that I use a lot in form1. But I can't get those 4 values for the life of me to show even in a messagebox on form 2. It just shows blank when using methods that pull information from a textBox.Text. I need to be able to use both instText and folder strings in other forms. Anyone got any ideas? The example I used is located on stackOverflow: [^] Thanks!

      J Offline
      J Offline
      Jibesh
      wrote on last edited by
      #2

      If you want to get the selected Item value, you can directly get the selected value using the combo.SelectedItem propety. but thats not the problem here for you. did you check the contents of instText has the data you selected? have you tried to debug this? what is the content of instText?? moreover in which method you call these lines?

      Guidelines for posting questions in the forum Jibesh V P

      G 1 Reply Last reply
      0
      • J Jibesh

        If you want to get the selected Item value, you can directly get the selected value using the combo.SelectedItem propety. but thats not the problem here for you. did you check the contents of instText has the data you selected? have you tried to debug this? what is the content of instText?? moreover in which method you call these lines?

        Guidelines for posting questions in the forum Jibesh V P

        G Offline
        G Offline
        Goaty65109
        wrote on last edited by
        #3

        Figured it out, dunno how I mucked it up at first, here's how you do it correctly. my button from form1

        private void buttonSched_Click(object sender, EventArgs e)
        {
        string instText = comboInst.GetItemText(comboInst.SelectedItem);
        string folder = instText.Substring(0, 4);
        Schedule Open = new Schedule(instText);
        Open.Show();
        }

        Calling is in form2:

        public partial class Form2 : Form
        {
        private string start;

            public Form2(string inst)
            {
                InitializeComponent();
                this.start = inst;
            }
        

        private void Schedule_Load(object sender, EventArgs e)
        {

                System.Windows.Forms.MessageBox.Show(start);
        

        }

        Quite simple, I know, but I was thinking too much into something that didn't really need that deep of thought. Thanks for the looks! Hope this helps someone in the future. BTW - you can alter the string after it's been called to the new form. I.E.

        System.Windows.Forms.MessageBox.Show(start.Substring(0, 4));

        This is what I needed the code to do, grab the first 4 characters from the string. Now I can use the string raw, or formatted if I like. Thanks again!

        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