I have a small application that has several checkboxes, a submit button, and a textbox. I want the user to be able to check what they want, click the submit button, and have the results display in the textbox. The application runs but instead of the values displaying I get "System.Collections.Generic.List`1[System.String]" displayed in the textbox. I am very new to this and would appreciate any help. My code is as follows...
namespace MY_App
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List<string> ls = new List<string>();
private void Checkbox1_CheckedChanged(object sender, EventArgs e)
{
ls.Add( "P.C. ");
}
private void Checkbox2_CheckedChanged(object sender, EventArgs e)
{
ls.Add( "WYSE Terminal" );
}
private void Checkbox3_CheckedChanged(object sender, EventArgs e)
{
ls.Add("Dual Monitors ");
}
private void button1_Click(object sender, EventArgs e)
{
string line = string.Join(",", ls.ToString());
textBoxTEST.Text = line;
}
private void textBoxTEST_TextChanged(object sender, EventArgs e)
{
}
You are trying to concat the object name, because of ls.ToString() will returns exactly what you've got in your TextBox.
Instead, use the following:
string line = string.Join(",", ls.ToArray());
textBoxTEST.Text = line;
Also, here is Linq solution:
ls.Aggregate((i, j) => i + ","+ j)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With