c# winforms
I have to following string:
1,07,19,19,07
2,19,07,07,19
3,08,20,08,20
I need each line to place into separate DataGridViewRow, and each part of line (split by comma) into separate DataGridViewColumn:
1 07 19 19 07
2 19 07 07 19
3 08 20 08 20
Please, help.

VulpesPosted Jun 18, 2012, 3:23 PM
If instead you have an array of 3 strings, 'lines', then just ignore the first line of code:
VulpesPosted Jun 18, 2012, 4:56 PM
I'd forgotten that the Rows.Add method has an overload which allows you to populate all cells from an array so that's a nice touch too :)
MementoPosted Jun 18, 2012, 4:26 PM
I found that these code also works. Could you, please give me your opinion:
object val = dgvObs.Rows[0].Cells[2].Value;
if (val == null) return;
string text = val.ToString();
using (StringReader sr = new StringReader(text))
{
string line;
while ((line = sr.ReadLine()) != null)
{
string[] divLine = line.Split(',');
dgvSm.Rows.Add(divLine);
}
}
VulpesPosted Jun 18, 2012, 4:07 PM
MementoPosted Jun 18, 2012, 3:51 PM
I'm just interesting - is here possible to write foreach line loop ?
If it is - please give me just a first line or two.
Because, next time maybe starting string could have more lines.
And congratulations for new forum design, especially for the "accepted" tape. Very nice.
VulpesPosted Jun 18, 2012, 2:47 PM