0

So, I have this binding source:

 List<archive> list = _context.archive.Include(t => t.partner1).Include(t => t.partner).Include(t => t.document_type).ToList();

 list = list.OrderBy(d => d.issuing_date).ToList();
 BindingList<archive> bindingList = new BindingList<archive>(list);

this._view.ArchivekDatasource.DataSource = bindingList;
this._view.DocumentTypeDatasource.DataSource = _context.document_type.Local.ToBindingList();
this._view.PartnerDatasource.DataSource = _context.partner.Local.ToBindingList();

So, archive has two fields that are represented as datetime in the database. But I just want to have them as date when shown in data grid view... How can I do this?

I know there is the truncate_time function, but I don't know how to use it to create a binding source as I want.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Whirlwind
  • 14,286
  • 11
  • 68
  • 157
  • I believe this has already been answered [here](https://stackoverflow.com/questions/4033113/how-to-format-datetime-columns-in-datagridview). – s.m. Oct 05 '18 at 06:57
  • @s.m. Somehow it didn't work. I tried to set it before setting an actually datasource. – Whirlwind Oct 05 '18 at 07:08
  • If you define your columns beforehand, use a `CellTemplate.ValueType` of type `DateTime` with `.Style = new DefaultCellStyle() { Format = "MM/dd/yyyy"}`. If not, after bindind the list, `dataGridView1.Columns[].CellTemplate.ValueType = typeof(DateTime);` `dataGridView1.Columns[].DefaultCellStyle.Format = "MM/dd/yyyy";` – Jimi Oct 05 '18 at 07:14

1 Answers1

0

Use this:

list = list.OrderBy(d => String.Format("{0:MM dd YYYY}", d.issuing_date)).ToList();

Maybe it can help.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rajan Mishra
  • 1,178
  • 2
  • 14
  • 30
  • What I did is ` list = list.OrderBy(d => String.Format("{0:mm:dd:yyyy}", d.issuing_date)).ToList();` and there was no change. I changed only single quotes to double quotes from your example. – Whirlwind Oct 05 '18 at 07:08