I have a datagridview in my winforms c# app in .net 3.5 and visual studio 2008.
From code, in the form constructor, and after InitializeComponent() method I set the datagridview's datasource as below:
this.dtItems = new DataTable();
this.dgv.DataSource = this.dtItems;
dtItems.Columns.Add(String.Empty, typeof(byte[])); // This will contain a png image, and I do not want to put a header text so string.empty used but it does not work
dtItems.Columns.Add("Date", typeof(DateTime));
dtItems.Columns.Add("ID", typeof(string));
dtItems.Columns.Add("Name", typeof(string));
dtItems.Columns.Add("Department", typeof(string));
dtItems is a private global variable of DataTable type:
private DataTable dtItems = null;
Problems I have:
- I would like to add first column with no header text but it is not working.
- When running, empty datatable is associated correctly to datagridview's datasource but one extra column is added at the leftmost. Why?
Updated:
Second point solved by using below line of code:
dgv.RowHeadersVisible = false;
not working
what do you mean, it doesn't display column or something else? – Aleksa Risticdgv
before you even set properties fordtItems
. Try movingthis.dgv.DataSource
after allColumns.Add
– Aleksa Ristic