简体   繁体   中英

How to append two different string array and display them in a multiline textbox

I am trying to read two columns from excel and display them in a multiline textbox. Currently my second array which represent the second column of the excel sheet is overwriting the first column array. Is there any way that I can display both the arrays in two lines within the same textbox.

Range col1 = ws.UsedRange.Columns[1];
                Range col2 = ws.UsedRange.Columns[2];
                System.Array col1values = (System.Array)col1.Cells.Value;
                System.Array col2values = (System.Array)col2.Cells.Value;
                string[] col1Array = col1values.OfType<object>().Select(o => o.ToString()).ToArray();
                string[] col2Array = col2values.OfType<object>().Select(o => o.ToString()).ToArray();

                textBox2.Text = String.Join(",", col1Array);
                textBox2.AppendText("\n");
                textBox2.Text = String.Join(",", col2Array);

You are setting the Text property of the textBox2 with the following line

textBox2.Text = String.Join(",", col2Array);

so all the things you have done in the upper lines disappears

Try something like

textBox2.Text = String.Join(",", col1Array);
textBox2.AppendText("\n");
textBox2.AppendText(String.Join(",", col2Array));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM