简体   繁体   中英

How to return the data of datagridview to listbox? c#

i was trying to get the values of my orders in datagridview and return the data like this

here's the code of saving to listbox to datagridview.

SaveCmd.Parameters.AddWithValue("@Orders", String.Join(", ", listBox1.Items.OfType<string>().ToArray()));

and this is the code to preview it on the listbox from datagridview listBox1.Items.Add(dataGridView1.CurrentRow.Cells[8].Value.ToString());

and it end up displaying like this xD

pls help, Thanks in advance!

Try This to preview each item inside dataGridView1.CurrentRow.Cells[8].Value to listBox1

dataGridView1.CurrentRow.Cells[8].Value.ToString().Split(',').ToList().ForEach(r => listBox1.Items.Add(r.Trim()));

or

listBox1.DataSource = dataGridView1.CurrentRow.Cells[8].Value.ToString().Split(',').ToList()

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