tags:

views:

41

answers:

1

Banging my head off the wall due to this. I'm getting the error at cell[rcell] = repack[counter] even though I have 190 items in the repack array.

        private string csvtogrid(string input)
    {
        input = input.Replace("\r", ",").Substring(2).TrimEnd(',').Trim().Replace("\n", ",").Replace(",,,", ",").Replace(",,",",");
        string[] repack = input.Split(',');
        string[] cell = { };
        int rcell = 1;
        for (int counter = 1; counter < repack.Length; counter++)
        {
            if (rcell < 4)
            {
                cell[rcell] = repack[counter];
                rcell++;
            }
            procgrid.Rows.Add(cell[1], cell[2], cell[3]);
            rcell = 1;
        }
        richTextBox1.Text = input;
        return null;
    }
+1  A: 

Your cell array is empty so you can't assign to element cell[rcell], since it doesn't exist.

string[] cell = { };

You should give it a size that is sufficiently large when you initialize it:

string[] cell = new string[4];
Mark Byers
Yep, that was it thank you. Will flag it as the answer once it lets me. Also, I'm trying to throw this into a datagrid but it's only going down one row.
MWC