autogenerate columns in datagridview

H

hazz

in a databound scenario I have a database column value that is of type
varchar with 3 discrete text values.
Binding to this table column with autogenerated columns displays the text
values in a DataGridViewTextBoxColumn column type.

I would like to display images as follows but I need to do so with the
DataGridViewImageColumn column type. How can I do that switcheroo ? Can I
set autogenerate columns to false and somehow transform the text values into
a new column that will accommodate the image display? thank you. -greg

private Bitmap Valid_Image;
Valid_Image = new Bitmap("green_ball.ico");

private void dataGridView1_CellFormatting(object sender,
System.Windows.Forms.DataGridViewCellFormattingEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name.Equals("Status")) {
String stringValue = e.Value as string;
switch (stringValue)
{
case "NV":
e.Value = NV_NotValidated_Image //cell display does not
display image but rather 'System.Drawing.Bitmap'
break;
case "V":
e.Value = V_Valid_Image;
break;
 
M

mark carew

Hi Hazz,
Remove the column, Insert(0, a new imagecolumn, Rebind the data source to
a lookup that returns the image file. This is just like the example in the
documentation on dataGridViewComboBoxColumn; but you are replacing a column
with an imageColumn rather that a comboboxColumn.
HTH
Mark
 
H

hazz

Working at the event level here was completely wrong. Creating the image
types prior to databinding was the solution.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top