[RESOLVED] Datagridview column datatypes
I'm having a slight issue displaying images in my DataGridView...
I am importing a CSV file to a datatable No problem.
I am then naming the column names like so dt.columns(0) = "Name" etc..
no problem so far..
I have a routine that looks for text and replaces it with an image, this also works as long as I create the column like so:
.Columns.AddRange( _
New DataGridViewTextBoxColumn(), _
New DataGridViewTextBoxColumn(), _
New DataGridViewTextBoxColumn(), _
New DataGridViewTextBoxColumn(), _
New DataGridViewTextBoxColumn(), _
New DataGridViewTextBoxColumn(), _
New DataGridViewTextBoxColumn(), _
New DataGridViewImageColumn()) ' Note that my last column is an image column...
Now, I use this command to import the datatable in to the datagrid:
dataGridView1.DataSource = dt
Of course I can't use the above method to create the image column as it will just add columns after ones I've already created so how can I change the datagridview column to display images before I use:
dataGridView1.DataSource = dt??
I need to be able to bind to the datatable and still be able to display images.
Any help would be great.
Re: Datagridview column datatypes
If you create the columns yourself and you want to bind data then you have to set the DataPropertyName of each column to tell it which column/property of the data source to bind to. You should create the columns in the designer rather than in code.
Re: Datagridview column datatypes
When I try to create the columns using the designer then a new set of columns are added at the end because I use dataGridView1.DataSource = dt This is the problem.
Re: Datagridview column datatypes
Ah, I think I understand... How do I bind a datatable column to a datagrid column?
Re: Datagridview column datatypes
Quote:
Originally Posted by
ElliotHC
Ah, I think I understand... How do I bind a datatable column to a datagrid column?
How I told you to do it in post #2. If you want an example then follow the CodeBank link in my signature and check out thread on putting a ComboBox Column In A DataGridView.
Re: Datagridview column datatypes