I just spent 10 minutes typing out an answer to your latest question, explaining that while I didn't have an answer, several possible workrounds occurred to me. Then I spotted the problem in your code. :laugh:
3 things.
1. The
e.FormattingApplied = true;
statement should only be used when you are sure that your formatting has worked, or at least will happen. Your code does not check that the right column is being processed.
2. The last line, where you assign the value is causing the error because it is trying to put the Persian date into the database. That won't work, hence the errors. it should assign the value to
e.Value
.
3. There is no need to put the code in a <code>for loop</code> the formatting gets applied for every row in the DataGridview anyway when the time comes for the data to be displayed.
Assuming that the code is for the same DataGridview as before it should look something like this:
private void OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 5)
{
e.FormattingApplied = true;
DateTime dtTemp =Convert.ToDateTime( dataGridView1.Rows[i].Cells[5].Value.ToString());
e.Value= DateUtility.Miladi2Shamsi(dtTemp);
}
else if (e.ColumnIndex == 6)
{
e.FormattingApplied = true;
string temp = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
switch (temp)
{
case "0":
e.Value = "Cashed";
break;
case 1:
e.Value = "Cancelled";
break;
case 2:
e.Value = "Not Cashed";
break;
default:
e.Value = "Returned";
break;
}
}
}
One last thing. I only noticed that you had another problem by accident. To attract the attention of someone who has answered one of your questions, you should do so by adding a comment to their answer (look at the bottom right of this answer and you will see the
Add Comment link in blue) just click that and type your comment. That way, the person will get an Email and will know you need more help. :)