Click here to Skip to main content
15,911,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

C#
How to program to accept a blank values for datetime columns into the grid and below is the line of code i'm getting error:

dataGridView1.Rows[RowCount - 1].Cells[cmbIdentity.Text].Value - Now i'm getting Index value is out of range.


C#
for (int RowCount = 1; RowCount <= strfile.Length - 1; RowCount++)
            {
                if (strfile[RowCount].ToString() != "")
                {
                    if (RowCount != 0)
                    {
                        string[] column = strfile[RowCount].Split('þ');
                        for (int i = 1; i < column.Length - 1; i++)
                        {
                            if (cmbColumnCombo.SelectedIndex == ((i - 1) / 2))
                            {
                                if (!string.IsNullOrEmpty(column[i]) && column[i].ToString() != "\u0014")
                                    {
                                        
                                        dataGridView1.Rows.Add();
                                        
                                        DateTime Time = Convert.ToDateTime(column[i].ToString());
                                        dataGridView1.Rows[RowCount - 1].Cells[txtColumnName.Text.Replace(" ", "")].Value = Time.ToString("HH:mm:ss");
                                        dataGridView1.Rows[RowCount - 1].Cells[cmbColumnCombo.Text].Value = Time.ToString("dd/MM/yyyy");
                                        //dataGridView1.Rows[RowCount - 1].Cells[cmbColumn1.Text].Value += column[i].ToString();

                                }
                            }
                        }
 
                        for (int i = 1; i < column.Length - 1; i++)
                        {
                            if (cmbIdentity.SelectedIndex == ((i - 1) / 2))
                            {
                                if (!string.IsNullOrEmpty(column[i]) && column[i].ToString() != "\u0014")
                                {
                                    dataGridView1.Rows[RowCount - 1].Cells[cmbIdentity.Text].Value += column[i].ToString();
                                }
                            }
                        }
                    }
                }
            }


C#
Can anyone please help me how to achieve this?


What I have tried:

I have changed the code and suggested to raise a new question for this.
Posted

1 solution

This is going to depend so much on the data you are processing that we can't fix it for you.
So start with the debugger. Put a breakpoint on the line that fails, and run your app. When it reaches the breakpoint, it will stop and let you take control.
You can look at variables, change them if you need to, even rewrite your code and continue!
So look at what your various indexes are exactly, and compare that to the tables you are accessing. When you find an index that doesn't fit, you can then start to look at why.
But we can't do any of that for you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900