471,354 Members | 1,293 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

autogenerate columns in datagridview

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.DataGridViewCellFormattingEve ntArgs 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;
Feb 11 '06 #1
2 8725
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
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.DataGridViewCellFormattingEve ntArgs 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;

Feb 12 '06 #2
Working at the event level here was completely wrong. Creating the image
types prior to databinding was the solution.

"hazz" <ha**@sonic.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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
u. -greg

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

private void dataGridView1_CellFormatting(object sender,
System.Windows.Forms.DataGridViewCellFormattingEve ntArgs 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;

Feb 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by ypul | last post: by
2 posts views Thread by serge calderara | last post: by
4 posts views Thread by Stropher | last post: by
3 posts views Thread by Paul Cheetham | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.