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:
C#
for (int RowCount = 1; RowCount 1; RowCount++) { if (strfile[RowCount].ToString() != "") { if (RowCount != 0) { string[] column = strfile[RowCount].Split('þ'); for (int i = 1; i 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 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(); } } } } } }
Shubham KumarRank #621 · 3.8K reputationPosted Feb 15, 2016, 1:28 AM EST
Aditya B6 reputationPosted Feb 15, 2016, 1:55 AM EST
ali tuncerRank #1,499 · 1.1K reputationPosted Feb 15, 2016, 8:46 PM EST
Do you have a date time picker control in you datagridview? which one is it?
if you assign empty string to a date time picker you will get an error like "cannot convert string to System.DateTime", it sounds like you have a different error, probably index value exceeds the size of the array...Try to debug step by step, check the value of variables..