Creating an 10 names via array from textbox on form 1 and then will show all names on form 2 via list box











up vote
-1
down vote

favorite














  1. Create an application with two forms. The first form must have two buttons. The first when clicked must accept a single name and store it in an array of up to 10 names. The second when clicked must open a separate form holding list box that has the names entered on the first form displayed in it. Do this in two ways
    (a) Transfer the names to the list box within the first form before displaying the second form
    (b) Transfer the names to the second form by making the array public static and place a button on the second form that when clicked will transfer the names from the array to the the list box



    enter code here
    FORM1:



     public partial class frm_main : Form
    {
    public static string str_name = new string[10];
    frm_display frm = new frm_display();
    int s;
    public frm_main()

    {

    InitializeComponent();
    }

    private void btn_store_Click(object sender, EventArgs e)
    {


    for (s = 0; s < str_name.Length; s++)
    {

    str_name[s] = txtBox_name.Text;
    frm.str_name[s] = str_name[s];


    }
    txtBox_name.Clear();
    txtBox_name.Focus();

    }

    private void btn_open_Click(object sender, EventArgs e)
    {


    frm.ShowDialog();

    }


    }




FORM 2:
public partial class frm_display : Form
{



    public string str_name= new string[10];

public frm_display()
{
InitializeComponent();
}


private void btn_showNames_Click(object sender, EventArgs e)
{


for (int s=0; s <str_name.Length;s++)
{

lstBox_names.Items.Add(str_name[s]);



}


}


it just show the last name placed in the textbox



Thank you










share|improve this question




























    up vote
    -1
    down vote

    favorite














    1. Create an application with two forms. The first form must have two buttons. The first when clicked must accept a single name and store it in an array of up to 10 names. The second when clicked must open a separate form holding list box that has the names entered on the first form displayed in it. Do this in two ways
      (a) Transfer the names to the list box within the first form before displaying the second form
      (b) Transfer the names to the second form by making the array public static and place a button on the second form that when clicked will transfer the names from the array to the the list box



      enter code here
      FORM1:



       public partial class frm_main : Form
      {
      public static string str_name = new string[10];
      frm_display frm = new frm_display();
      int s;
      public frm_main()

      {

      InitializeComponent();
      }

      private void btn_store_Click(object sender, EventArgs e)
      {


      for (s = 0; s < str_name.Length; s++)
      {

      str_name[s] = txtBox_name.Text;
      frm.str_name[s] = str_name[s];


      }
      txtBox_name.Clear();
      txtBox_name.Focus();

      }

      private void btn_open_Click(object sender, EventArgs e)
      {


      frm.ShowDialog();

      }


      }




    FORM 2:
    public partial class frm_display : Form
    {



        public string str_name= new string[10];

    public frm_display()
    {
    InitializeComponent();
    }


    private void btn_showNames_Click(object sender, EventArgs e)
    {


    for (int s=0; s <str_name.Length;s++)
    {

    lstBox_names.Items.Add(str_name[s]);



    }


    }


    it just show the last name placed in the textbox



    Thank you










    share|improve this question


























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite













      1. Create an application with two forms. The first form must have two buttons. The first when clicked must accept a single name and store it in an array of up to 10 names. The second when clicked must open a separate form holding list box that has the names entered on the first form displayed in it. Do this in two ways
        (a) Transfer the names to the list box within the first form before displaying the second form
        (b) Transfer the names to the second form by making the array public static and place a button on the second form that when clicked will transfer the names from the array to the the list box



        enter code here
        FORM1:



         public partial class frm_main : Form
        {
        public static string str_name = new string[10];
        frm_display frm = new frm_display();
        int s;
        public frm_main()

        {

        InitializeComponent();
        }

        private void btn_store_Click(object sender, EventArgs e)
        {


        for (s = 0; s < str_name.Length; s++)
        {

        str_name[s] = txtBox_name.Text;
        frm.str_name[s] = str_name[s];


        }
        txtBox_name.Clear();
        txtBox_name.Focus();

        }

        private void btn_open_Click(object sender, EventArgs e)
        {


        frm.ShowDialog();

        }


        }




      FORM 2:
      public partial class frm_display : Form
      {



          public string str_name= new string[10];

      public frm_display()
      {
      InitializeComponent();
      }


      private void btn_showNames_Click(object sender, EventArgs e)
      {


      for (int s=0; s <str_name.Length;s++)
      {

      lstBox_names.Items.Add(str_name[s]);



      }


      }


      it just show the last name placed in the textbox



      Thank you










      share|improve this question

















      1. Create an application with two forms. The first form must have two buttons. The first when clicked must accept a single name and store it in an array of up to 10 names. The second when clicked must open a separate form holding list box that has the names entered on the first form displayed in it. Do this in two ways
        (a) Transfer the names to the list box within the first form before displaying the second form
        (b) Transfer the names to the second form by making the array public static and place a button on the second form that when clicked will transfer the names from the array to the the list box



        enter code here
        FORM1:



         public partial class frm_main : Form
        {
        public static string str_name = new string[10];
        frm_display frm = new frm_display();
        int s;
        public frm_main()

        {

        InitializeComponent();
        }

        private void btn_store_Click(object sender, EventArgs e)
        {


        for (s = 0; s < str_name.Length; s++)
        {

        str_name[s] = txtBox_name.Text;
        frm.str_name[s] = str_name[s];


        }
        txtBox_name.Clear();
        txtBox_name.Focus();

        }

        private void btn_open_Click(object sender, EventArgs e)
        {


        frm.ShowDialog();

        }


        }




      FORM 2:
      public partial class frm_display : Form
      {



          public string str_name= new string[10];

      public frm_display()
      {
      InitializeComponent();
      }


      private void btn_showNames_Click(object sender, EventArgs e)
      {


      for (int s=0; s <str_name.Length;s++)
      {

      lstBox_names.Items.Add(str_name[s]);



      }


      }


      it just show the last name placed in the textbox



      Thank you







      c#






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 6 at 7:35

























      asked Nov 6 at 7:09









      ced gonzales

      11




      11
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          You are return; in loop so loop has stopped there. Please remove it.



          Instead of storing it to static members, you can directly pass array through parameter.



          In form 2



          public frm_display(Array ary) // Here you will get array you passed from form1
          {

          }


          In form 1



          private void btn_open_Click(object sender, EventArgs e)
          {
          form2 frm= new form2(YourArrayHere);
          frm.ShowDialog();
          }





          share|improve this answer





















          • i removed the return; but it only one name appears.
            – ced gonzales
            Nov 6 at 7:24










          • Please remove for loop from btn_store_Click and store a TextBox values in array at once. Items will be store on click with changed values in TextBox on each Button click. Then same values you will receive on another form.
            – Nakul
            Nov 6 at 7:30










          • is it alright if you can edit my code?
            – ced gonzales
            Nov 6 at 7:37


















          up vote
          -1
          down vote













          Instead of array suggest to use List
          Form1



          public static List str_name = new List();



          private void btn_store_Click(object sender, EventArgs e)
          {
          str_name.Add(txtBox_name.Text);
          }


          Form2



          foreach(string str in str_name )
          {
          //here you will get each string in str variable
          }





          share|improve this answer























          • Please correct above line public static List<String> str_name = new List<String> ();
            – Nakul
            Nov 6 at 7:51












          • str_name.Add = txtBox_name.Text has errors. Add cannot be used
            – ced gonzales
            Nov 6 at 8:17










          • because this answer is not c#
            – sLw
            Nov 6 at 8:18












          • Please use List as Add is method of List not array
            – Nakul
            Nov 6 at 9:10










          • it should be str_name.Add(txtBox_name.Text)
            – ced gonzales
            Nov 8 at 3:23











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53167234%2fcreating-an-10-names-via-array-from-textbox-on-form-1-and-then-will-show-all-nam%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          You are return; in loop so loop has stopped there. Please remove it.



          Instead of storing it to static members, you can directly pass array through parameter.



          In form 2



          public frm_display(Array ary) // Here you will get array you passed from form1
          {

          }


          In form 1



          private void btn_open_Click(object sender, EventArgs e)
          {
          form2 frm= new form2(YourArrayHere);
          frm.ShowDialog();
          }





          share|improve this answer





















          • i removed the return; but it only one name appears.
            – ced gonzales
            Nov 6 at 7:24










          • Please remove for loop from btn_store_Click and store a TextBox values in array at once. Items will be store on click with changed values in TextBox on each Button click. Then same values you will receive on another form.
            – Nakul
            Nov 6 at 7:30










          • is it alright if you can edit my code?
            – ced gonzales
            Nov 6 at 7:37















          up vote
          0
          down vote













          You are return; in loop so loop has stopped there. Please remove it.



          Instead of storing it to static members, you can directly pass array through parameter.



          In form 2



          public frm_display(Array ary) // Here you will get array you passed from form1
          {

          }


          In form 1



          private void btn_open_Click(object sender, EventArgs e)
          {
          form2 frm= new form2(YourArrayHere);
          frm.ShowDialog();
          }





          share|improve this answer





















          • i removed the return; but it only one name appears.
            – ced gonzales
            Nov 6 at 7:24










          • Please remove for loop from btn_store_Click and store a TextBox values in array at once. Items will be store on click with changed values in TextBox on each Button click. Then same values you will receive on another form.
            – Nakul
            Nov 6 at 7:30










          • is it alright if you can edit my code?
            – ced gonzales
            Nov 6 at 7:37













          up vote
          0
          down vote










          up vote
          0
          down vote









          You are return; in loop so loop has stopped there. Please remove it.



          Instead of storing it to static members, you can directly pass array through parameter.



          In form 2



          public frm_display(Array ary) // Here you will get array you passed from form1
          {

          }


          In form 1



          private void btn_open_Click(object sender, EventArgs e)
          {
          form2 frm= new form2(YourArrayHere);
          frm.ShowDialog();
          }





          share|improve this answer












          You are return; in loop so loop has stopped there. Please remove it.



          Instead of storing it to static members, you can directly pass array through parameter.



          In form 2



          public frm_display(Array ary) // Here you will get array you passed from form1
          {

          }


          In form 1



          private void btn_open_Click(object sender, EventArgs e)
          {
          form2 frm= new form2(YourArrayHere);
          frm.ShowDialog();
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 6 at 7:16









          Nakul

          1048




          1048












          • i removed the return; but it only one name appears.
            – ced gonzales
            Nov 6 at 7:24










          • Please remove for loop from btn_store_Click and store a TextBox values in array at once. Items will be store on click with changed values in TextBox on each Button click. Then same values you will receive on another form.
            – Nakul
            Nov 6 at 7:30










          • is it alright if you can edit my code?
            – ced gonzales
            Nov 6 at 7:37


















          • i removed the return; but it only one name appears.
            – ced gonzales
            Nov 6 at 7:24










          • Please remove for loop from btn_store_Click and store a TextBox values in array at once. Items will be store on click with changed values in TextBox on each Button click. Then same values you will receive on another form.
            – Nakul
            Nov 6 at 7:30










          • is it alright if you can edit my code?
            – ced gonzales
            Nov 6 at 7:37
















          i removed the return; but it only one name appears.
          – ced gonzales
          Nov 6 at 7:24




          i removed the return; but it only one name appears.
          – ced gonzales
          Nov 6 at 7:24












          Please remove for loop from btn_store_Click and store a TextBox values in array at once. Items will be store on click with changed values in TextBox on each Button click. Then same values you will receive on another form.
          – Nakul
          Nov 6 at 7:30




          Please remove for loop from btn_store_Click and store a TextBox values in array at once. Items will be store on click with changed values in TextBox on each Button click. Then same values you will receive on another form.
          – Nakul
          Nov 6 at 7:30












          is it alright if you can edit my code?
          – ced gonzales
          Nov 6 at 7:37




          is it alright if you can edit my code?
          – ced gonzales
          Nov 6 at 7:37












          up vote
          -1
          down vote













          Instead of array suggest to use List
          Form1



          public static List str_name = new List();



          private void btn_store_Click(object sender, EventArgs e)
          {
          str_name.Add(txtBox_name.Text);
          }


          Form2



          foreach(string str in str_name )
          {
          //here you will get each string in str variable
          }





          share|improve this answer























          • Please correct above line public static List<String> str_name = new List<String> ();
            – Nakul
            Nov 6 at 7:51












          • str_name.Add = txtBox_name.Text has errors. Add cannot be used
            – ced gonzales
            Nov 6 at 8:17










          • because this answer is not c#
            – sLw
            Nov 6 at 8:18












          • Please use List as Add is method of List not array
            – Nakul
            Nov 6 at 9:10










          • it should be str_name.Add(txtBox_name.Text)
            – ced gonzales
            Nov 8 at 3:23















          up vote
          -1
          down vote













          Instead of array suggest to use List
          Form1



          public static List str_name = new List();



          private void btn_store_Click(object sender, EventArgs e)
          {
          str_name.Add(txtBox_name.Text);
          }


          Form2



          foreach(string str in str_name )
          {
          //here you will get each string in str variable
          }





          share|improve this answer























          • Please correct above line public static List<String> str_name = new List<String> ();
            – Nakul
            Nov 6 at 7:51












          • str_name.Add = txtBox_name.Text has errors. Add cannot be used
            – ced gonzales
            Nov 6 at 8:17










          • because this answer is not c#
            – sLw
            Nov 6 at 8:18












          • Please use List as Add is method of List not array
            – Nakul
            Nov 6 at 9:10










          • it should be str_name.Add(txtBox_name.Text)
            – ced gonzales
            Nov 8 at 3:23













          up vote
          -1
          down vote










          up vote
          -1
          down vote









          Instead of array suggest to use List
          Form1



          public static List str_name = new List();



          private void btn_store_Click(object sender, EventArgs e)
          {
          str_name.Add(txtBox_name.Text);
          }


          Form2



          foreach(string str in str_name )
          {
          //here you will get each string in str variable
          }





          share|improve this answer














          Instead of array suggest to use List
          Form1



          public static List str_name = new List();



          private void btn_store_Click(object sender, EventArgs e)
          {
          str_name.Add(txtBox_name.Text);
          }


          Form2



          foreach(string str in str_name )
          {
          //here you will get each string in str variable
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 8 at 6:52

























          answered Nov 6 at 7:51









          Nakul

          1048




          1048












          • Please correct above line public static List<String> str_name = new List<String> ();
            – Nakul
            Nov 6 at 7:51












          • str_name.Add = txtBox_name.Text has errors. Add cannot be used
            – ced gonzales
            Nov 6 at 8:17










          • because this answer is not c#
            – sLw
            Nov 6 at 8:18












          • Please use List as Add is method of List not array
            – Nakul
            Nov 6 at 9:10










          • it should be str_name.Add(txtBox_name.Text)
            – ced gonzales
            Nov 8 at 3:23


















          • Please correct above line public static List<String> str_name = new List<String> ();
            – Nakul
            Nov 6 at 7:51












          • str_name.Add = txtBox_name.Text has errors. Add cannot be used
            – ced gonzales
            Nov 6 at 8:17










          • because this answer is not c#
            – sLw
            Nov 6 at 8:18












          • Please use List as Add is method of List not array
            – Nakul
            Nov 6 at 9:10










          • it should be str_name.Add(txtBox_name.Text)
            – ced gonzales
            Nov 8 at 3:23
















          Please correct above line public static List<String> str_name = new List<String> ();
          – Nakul
          Nov 6 at 7:51






          Please correct above line public static List<String> str_name = new List<String> ();
          – Nakul
          Nov 6 at 7:51














          str_name.Add = txtBox_name.Text has errors. Add cannot be used
          – ced gonzales
          Nov 6 at 8:17




          str_name.Add = txtBox_name.Text has errors. Add cannot be used
          – ced gonzales
          Nov 6 at 8:17












          because this answer is not c#
          – sLw
          Nov 6 at 8:18






          because this answer is not c#
          – sLw
          Nov 6 at 8:18














          Please use List as Add is method of List not array
          – Nakul
          Nov 6 at 9:10




          Please use List as Add is method of List not array
          – Nakul
          Nov 6 at 9:10












          it should be str_name.Add(txtBox_name.Text)
          – ced gonzales
          Nov 8 at 3:23




          it should be str_name.Add(txtBox_name.Text)
          – ced gonzales
          Nov 8 at 3:23


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53167234%2fcreating-an-10-names-via-array-from-textbox-on-form-1-and-then-will-show-all-nam%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()