I have a DataGridView
called DGVpresale, it has all the data from a DataTable called presale
Here's how I'm filling it:
private void fillDGVpresale()
{
try
{
DBconnection.Open();
}
catch
{ }
string sqlQuery = "SELECT * FROM presale";
using (MySqlDataAdapter da = new MySqlDataAdapter(sqlQuery, DBconnection))
{
using (DataTable dt = new DataTable())
{
da.Fill(dt);
DGVpresale.DataSource = dt;
DGVpresale.Columns["SELLER"].HeaderText = "Seller";
DGVpresale.Columns["CLIENT"].HeaderText = "Client";
DGVpresale.Columns["REGDATE"].HeaderText = "Registration Date";
DGVpresale.Columns["SELLER"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
DGVpresale.Columns["CLIENT"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
DGVpresale.Columns["REGDATE"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader;
}
}
}
I've translated table & column names and deleted some useless ones
There's a Date Column called REGDATE
, which saves all dates in this format: yyyy-MM-dd
I want to change the format inside my DataGridView to dd/MM/yyyy
I tried this:
DGVpresale.Columns["REGDATE"].DefaultCellStyle.Format = "dd/MM/yyyy";
But nothing changes and I can't find any other way to do this.
I don't know if changes anything, but since I had an error when trying to fill the datagridview I had to add this to my DBconnection: convert zero datetime=True