Reputation: 123
There is my reading to DGV
public void ReadFromDB()
{
dataset = DB.ReadFromDB("SELECT * FROM orders");
dataGridView1.DataSource = dataset.Tables[0];
//another columns....
DataGridViewColumn sellDate = new DataGridViewTextBoxColumn();
sellDate.DataPropertyName = "sell_date";
sellDate.ReadOnly = true;
sellDate.Name = "Дата продажи";
dataGridView1.Columns.Add(sellDate);
dataGridView1.Columns[4].DefaultCellStyle.Format = "dd/MM/yyyy";
dataGridView1.Columns[4].Width = 80;
dataGridView1.Update();
}
Why formatting doesn't work? DefaultCellStyle.Format is set:
Upvotes: 1
Views: 20292
Reputation: 105
just in case if someone is looking for the answer to this question...
dataGridView1.Columns[4].DefaultCellStyle.Format = "dd'/'MM'/'yyyy";
all you have to do is add single quotations before and after the slash like this '/'
Upvotes: 3
Reputation: 5373
it may be the slash/backslash issue. Try this:
dataGridView1.Columns[4].DefaultCellStyle.Format = "dd\\/MM\\/yyyy";
or
dataGridView1.Columns[4].DefaultCellStyle.Format = @"dd\/MM\/yyyy";
Upvotes: 0
Reputation: 283
If your getting this from the database, its getting the format from your table.
Upvotes: 0
Reputation: 2630
Make sure that the column index is [4] or [5]. You can check it from designer also.
Also make sure that the column is of DateTime type then only it will be get formatted.
Upvotes: 0