473,668 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 DataGridViewTex tBoxColumn column type.

I would like to display images as follows but I need to do so with the
DataGridViewIma geColumn 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_b all.ico");

private void dataGridView1_C ellFormatting(o bject sender,
System.Windows. Forms.DataGridV iewCellFormatti ngEventArgs e)
{
if (dataGridView1. Columns[e.ColumnIndex].Name.Equals("S tatus")) {
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 8858
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 dataGridViewCom boBoxColumn; 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 DataGridViewTex tBoxColumn column type.

I would like to display images as follows but I need to do so with the
DataGridViewIma geColumn 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_b all.ico");

private void dataGridView1_C ellFormatting(o bject sender,
System.Windows. Forms.DataGridV iewCellFormatti ngEventArgs e)
{
if (dataGridView1. Columns[e.ColumnIndex].Name.Equals("S tatus")) {
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******** ********@TK2MSF TNGP09.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 DataGridViewTex tBoxColumn column type.

I would like to display images as follows but I need to do so with the
DataGridViewIma geColumn 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_b all.ico");

private void dataGridView1_C ellFormatting(o bject sender,
System.Windows. Forms.DataGridV iewCellFormatti ngEventArgs e)
{
if (dataGridView1. Columns[e.ColumnIndex].Name.Equals("S tatus")) {
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
1705
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 that has the information, but we as developers have no way to access this information. I have come up with a solution for the problem, (as I am sure many others have) using reflection. Here is some sample code that will print out the auto...
2
864
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 that has the information, but we as developers have no way to access this information. I have come up with a solution for the problem, (as I am sure many others have) using reflection. Here is some sample code that will print out the auto...
1
1736
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 be hyperlinks, so that I can navigate from that page to another, depending on the link clicked. how can I do in autogenerate columns
2
1464
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 the content click cell to the next page as a parameter. I can do that without any trouble if my grid is not set for autogenerate. How can I do when columns name are issue from the dataset ?
4
22116
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 = false; //mobiltelefon When I run the programm, the columns are still displayed. I am developing with Visual C#2005 Express Edition Beta.
8
34269
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 my data. (AutoGenerateColumns is true). The data is 2 columns of System.String cell. 4. If I assign the DataTable to DataGridView.DataSource, I get 4 columns. 2
3
2871
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 the DataGrid control in .Net 1, each Column had a property that allowed it to be bound to a column in a datatable, so I could define the columns of the grid, and which columns they related to in its datasource, and they were all that would display.
0
6241
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 defined (defined columns collection) in a DataGridView?? i.e. sql_query.display_name = dataGridView1.dg1vc_display_name sql_query.name_last = dataGridView1.name_last sql_query.name_first =...
6
10605
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 to a DataTable, and then loop through the rows setting the background colour of the last cell to LightGrey and the cell itself to read-only if the column value is true. After the form finishes loading the code didn't work i.e. the cells are not set...
0
8459
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8378
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8890
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8653
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7398
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2786
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2018
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1783
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.