I have a function to which an array has a large sum of CSV imported split data. I currently have it set as the code below however I'm having some issues getting the data to go into the separate columns than into a single one. What I would like to achieve is a non-redundant means of supplying a function a string array of any size, and define how many columns across the data must be read before adding it as a row into the DataGrid.
private string csvtogrid(string input, columns)
{
input = input.Replace("\r", ",").Substring(2).TrimEnd(',').Trim().Replace("\n", ",").Replace(",,,", ",").Replace(",,",",");
string[] repack = input.Split(',');
string[] cell = new string[columns];
int rcell = 0;
for (int counter = 1; counter < repack.Length; counter++)
{
if (rcell < columns)
{
cell[rcell] = repack[counter];
rcell++;
}
//MessageBox.Show(cell[0] + cell[1] + cell[2]);
procgrid.Rows.Add(cell[0], cell[1], cell[2]);
rcell = 0;
}
return null;
}