|
-
May 24th, 2013, 08:50 AM
#1
Thread Starter
New Member
[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.
-
May 24th, 2013, 09:27 AM
#2
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.
-
May 24th, 2013, 09:42 AM
#3
Thread Starter
New Member
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.
-
May 24th, 2013, 09:48 AM
#4
Thread Starter
New Member
Re: Datagridview column datatypes
Ah, I think I understand... How do I bind a datatable column to a datagrid column?
-
May 24th, 2013, 10:16 AM
#5
Re: Datagridview column datatypes
 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.
-
May 24th, 2013, 11:52 AM
#6
Thread Starter
New Member
Re: Datagridview column datatypes
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|