473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 8841
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jason Coyne Gaijin42 | last post by:
I have seen several people looking for a way to access the Columns collection when using the AutoGenerate = true option. Some people have gotten so far as to find the private autoGenColumnsArray...
2
by: Jason Coyne Gaijin42 | last post by:
I have seen several people looking for a way to access the Columns collection when using the AutoGenerate = true option. Some people have gotten so far as to find the private autoGenColumnsArray...
1
by: ypul | last post by:
Hi , Getting to the point directly, my query output doesnt have fixed columns , so I choosed "autogenerate columns" datagrid. I assign this dataset to my datagrid, but now I want my data should...
2
by: serge calderara | last post by:
Dear all, I have a datagrid which bind to a dataset object Datagrid autogenerate propertie is set to True. I need to create the first column of my grid to be used as an hyperlink and sending...
4
by: Stropher | last post by:
I have the following: this.dataGridViewBill.DataSource = tblResult; //hide the following columns this.dataGridViewBill.Columns.Visible = false; //email this.dataGridViewBill.Columns.Visible =...
8
by: George | last post by:
Hi, I have been trying to see if I can do the following: 1. Create a DataGridView 2. Create 2 columns in the DataGridView (1 textbox and the other combobox) 3. Create a DataTable containing...
3
by: Paul Cheetham | last post by:
Hi, I have a DataGridView control, and I am using it's datasource property to assign a datatable to it at runtime. The datatable has some columns in it that I don't want to be visible. With...
0
by: frostbb | last post by:
Ok, stumped one more time, I'm trying to learn how to use a DataGridView in place of the old DataGrid control. QUESTION: How do I map the columns returned from a RunTime sql query to the columns...
6
by: Ciaran | last post by:
I'm having a really strange issue with the DataGridView control in a VS2008 / .NET 3.5 winforms project. I have a simple form with a grid. In the form constructor I call a function to bind the grind...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.