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
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#
add a comment |
up vote
-1
down vote
favorite
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#
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
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#
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#
c#
edited Nov 6 at 7:35
asked Nov 6 at 7:09
ced gonzales
11
11
add a comment |
add a comment |
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();
}
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
add a comment |
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
}
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
|
show 1 more comment
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();
}
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
add a comment |
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();
}
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
add a comment |
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();
}
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();
}
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
add a comment |
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
add a comment |
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
}
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
|
show 1 more comment
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
}
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
|
show 1 more comment
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
}
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
}
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
|
show 1 more comment
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
|
show 1 more comment
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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