Aditya B

Aditya B

  • NA
  • 6
  • 2.9k

Error while splitting the datetime fields

Feb 15 2016 6:19 AM
Hi,

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.


My total code is:
 
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();                                 }                             }                         }                     }                 }             }
 Can anyone please help me how to achieve this?
 

Answers (3)