I use Microsoft SQL server to save and retrieve DateTime. But in our culture, users use Persian date time. So i wrote a extension method ToPersianDateString(this DateTime dt) to display users the correct Persian date instate of Gregorian date.
Problem occurs when DataGridView want’s to display data or after user edits Persian date value. Is there a way to specify DataGridView to call my function for date time columns and after user edits date time column, converts it to Gregorian date time?
I also have a static function for converting to Gregorian date:
static DateTime ToGregorianDate(string persianDate);
I’m using Linq to SQL as ORM and my sample form is like this:
public class PeopleForm : Form
{
DataContext context = new DataContext();
public PeopleForm()
{
InitializeComponents();
datagridview1.DataSource = context.People;
}
private void btnSave_Click(...)
{
try{
context.SubmitChanges();
}
catch
{
MessageBox.Show(...);
}
}
}
Have you tried using
DataGridView.CellFormattingEvent?