Jevon Jevon - 21 days ago 7
C# Question

appendLine in cell next to the previous value

I have this function that executes on a button click.

private void button9_Click(object sender, EventArgs e)
{
StringBuilder csvconten = new StringBuilder();
csvconten.AppendLine(comboBox1.Text).AppendLine(comboBox2.Text);
string csvpath = "cross_check2.csv";
File.AppendAllText(csvpath, csvconten.ToString());
}


In this block of code:

csvconten.AppendLine(comboBox1.Text).AppendLine(comboBox2.Text);


I want the comoBox2.Text value to appear next to comboBox1.Text. currently it keeps going under comboBox2.Text. How do I get it beside it in the next cell?
Let me repeat, beside it i the next cell not in the same cell. it would be comboBox2.Text in cell A and comboBox2.Text in cell B

Answer

You're writing a csv file, your line of code appends it as a new line

This will append a single line separated by a comma.

csvconten.AppendFormat("{0},{1}\r\n",comboBox1.Text,comboBox2.Text);
Comments