473,698 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGridView row background color

Hi, all,

Is there any way to change DataGridView row color based on different row
data? for example, if row data in first column = 1, it is yellow, if it is 2,
it is blue, if 3 it is white. That means how to loop DataGridData to get row
data, then based on the different data to change row background color?

Thanks in advance!
Jun 26 '06 #1
6 24770
Hello martin1,
after some modifications this will do...

Dim CountR As Integer

For CountR = 0 To GridView1.Rows. Count - 1
Select Case GridView1.Rows( CountR).Cells(1 ).Text
Case "Austria" : GridView1.Rows( CountR).BackCol or = Drawing.Color.Y ellow
Case "Brazil" : GridView1.Rows( CountR).BackCol or = Drawing.Color.V iolet
Case "Belgium" : GridView1.Rows( CountR).BackCol or = Drawing.Color.A qua
Case Else : GridView1.Rows( CountR).BackCol or = Drawing.Color.C oral
End Select

Next
Jack

Hi, all,

Is there any way to change DataGridView row color based on different
row data? for example, if row data in first column = 1, it is yellow,
if it is 2, it is blue, if 3 it is white. That means how to loop
DataGridData to get row data, then based on the different data to
change row background color?

Thanks in advance!

Jun 27 '06 #2
Thank you. Jack

another question is do yuo know how to remove some columns from
DataGridView? whcih feature and function is used for this? Thanks

"Jack" wrote:
Hello martin1,
after some modifications this will do...

Dim CountR As Integer

For CountR = 0 To GridView1.Rows. Count - 1
Select Case GridView1.Rows( CountR).Cells(1 ).Text
Case "Austria" : GridView1.Rows( CountR).BackCol or = Drawing.Color.Y ellow
Case "Brazil" : GridView1.Rows( CountR).BackCol or = Drawing.Color.V iolet
Case "Belgium" : GridView1.Rows( CountR).BackCol or = Drawing.Color.A qua
Case Else : GridView1.Rows( CountR).BackCol or = Drawing.Color.C oral
End Select

Next
Jack

Hi, all,

Is there any way to change DataGridView row color based on different
row data? for example, if row data in first column = 1, it is yellow,
if it is 2, it is blue, if 3 it is white. That means how to loop
DataGridData to get row data, then based on the different data to
change row background color?

Thanks in advance!


Jun 27 '06 #3

martin1 wrote:
Thank you. Jack

another question is do yuo know how to remove some columns from
DataGridView? whcih feature and function is used for this? Thanks

"Jack" wrote:
Hello martin1,
after some modifications this will do...

Dim CountR As Integer

For CountR = 0 To GridView1.Rows. Count - 1
Select Case GridView1.Rows( CountR).Cells(1 ).Text
Case "Austria" : GridView1.Rows( CountR).BackCol or = Drawing.Color.Y ellow
Case "Brazil" : GridView1.Rows( CountR).BackCol or = Drawing.Color.V iolet
Case "Belgium" : GridView1.Rows( CountR).BackCol or = Drawing.Color.A qua
Case Else : GridView1.Rows( CountR).BackCol or = Drawing.Color.C oral
End Select

Next
Jack

Hi, all,

Is there any way to change DataGridView row color based on different
row data? for example, if row data in first column = 1, it is yellow,
if it is 2, it is blue, if 3 it is white. That means how to loop
DataGridData to get row data, then based on the different data to
change row background color?

Thanks in advance!



If the datasource is a datatable.

Table.Columns(C olumn_Name).Col umnMapping() = MappingType.Hid den

B.

Jun 27 '06 #4
Thank you. Brian,

how about datasource is DataGridView? which is pupulated from dataset

"Brian Tkatch" wrote:

martin1 wrote:
Thank you. Jack

another question is do yuo know how to remove some columns from
DataGridView? whcih feature and function is used for this? Thanks

"Jack" wrote:
Hello martin1,
after some modifications this will do...

Dim CountR As Integer

For CountR = 0 To GridView1.Rows. Count - 1
Select Case GridView1.Rows( CountR).Cells(1 ).Text
Case "Austria" : GridView1.Rows( CountR).BackCol or = Drawing.Color.Y ellow
Case "Brazil" : GridView1.Rows( CountR).BackCol or = Drawing.Color.V iolet
Case "Belgium" : GridView1.Rows( CountR).BackCol or = Drawing.Color.A qua
Case Else : GridView1.Rows( CountR).BackCol or = Drawing.Color.C oral
End Select

Next
Jack
> Hi, all,
>
> Is there any way to change DataGridView row color based on different
> row data? for example, if row data in first column = 1, it is yellow,
> if it is 2, it is blue, if 3 it is white. That means how to loop
> DataGridData to get row data, then based on the different data to
> change row background color?
>
> Thanks in advance!
>


If the datasource is a datatable.

Table.Columns(C olumn_Name).Col umnMapping() = MappingType.Hid den

B.

Jun 27 '06 #5
I figure now

DataGridView.Co lumns(colume_na me).Visible = False

"martin1" wrote:
Thank you. Brian,

how about datasource is DataGridView? which is pupulated from dataset

"Brian Tkatch" wrote:

martin1 wrote:
Thank you. Jack

another question is do yuo know how to remove some columns from
DataGridView? whcih feature and function is used for this? Thanks

"Jack" wrote:

> Hello martin1,
> after some modifications this will do...
>
> Dim CountR As Integer
>
> For CountR = 0 To GridView1.Rows. Count - 1
> Select Case GridView1.Rows( CountR).Cells(1 ).Text
> Case "Austria" : GridView1.Rows( CountR).BackCol or = Drawing.Color.Y ellow
> Case "Brazil" : GridView1.Rows( CountR).BackCol or = Drawing.Color.V iolet
> Case "Belgium" : GridView1.Rows( CountR).BackCol or = Drawing.Color.A qua
> Case Else : GridView1.Rows( CountR).BackCol or = Drawing.Color.C oral
> End Select
>
> Next
>
>
> Jack
>
>
> > Hi, all,
> >
> > Is there any way to change DataGridView row color based on different
> > row data? for example, if row data in first column = 1, it is yellow,
> > if it is 2, it is blue, if 3 it is white. That means how to loop
> > DataGridData to get row data, then based on the different data to
> > change row background color?
> >
> > Thanks in advance!
> >
>
>
>


If the datasource is a datatable.

Table.Columns(C olumn_Name).Col umnMapping() = MappingType.Hid den

B.

Jun 27 '06 #6
martin1 wrote:
Thank you. Brian,

how about datasource is DataGridView? which is pupulated from dataset

"Brian Tkatch" wrote:

martin1 wrote:
Thank you. Jack

another question is do yuo know how to remove some columns from
DataGridView? whcih feature and function is used for this? Thanks

"Jack" wrote:

> Hello martin1,
> after some modifications this will do...
>
> Dim CountR As Integer
>
> For CountR = 0 To GridView1.Rows. Count - 1
> Select Case GridView1.Rows( CountR).Cells(1 ).Text
> Case "Austria" : GridView1.Rows( CountR).BackCol or = Drawing.Color.Y ellow
> Case "Brazil" : GridView1.Rows( CountR).BackCol or = Drawing.Color.V iolet
> Case "Belgium" : GridView1.Rows( CountR).BackCol or = Drawing.Color.A qua
> Case Else : GridView1.Rows( CountR).BackCol or = Drawing.Color.C oral
> End Select
>
> Next
>
>
> Jack
>
>
> > Hi, all,
> >
> > Is there any way to change DataGridView row color based on different
> > row data? for example, if row data in first column = 1, it is yellow,
> > if it is 2, it is blue, if 3 it is white. That means how to loop
> > DataGridData to get row data, then based on the different data to
> > change row background color?
> >
> > Thanks in advance!
> >
>
>
>


If the datasource is a datatable.

Table.Columns(C olumn_Name).Col umnMapping() = MappingType.Hid den

B.


Then go up first. :)

MyDataGridView. DataSource.Tabl e.Columns(Colum n_Name).ColumnM apping() =
MappingType.Hid den

Just like every DataTable has a link to it's DefaultView every DataView
has a link to it's (parent) Table.

BTW, if you want context-sensitive help to appear, you have to tell the
editor whatr the DataSource is, since it otherwise will not know (since
it can be a DataSet, DataTable, DataView...), and this is (one of the
things) done via CType.

CType(MyDataGri dView.DataSourc e,
DataView).Table .Columns(Column _Name).ColumnMa pping() =
MappingType.Hid den
B.

Jun 28 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3481
by: Chris Beall | last post by:
I'm displaying an image that is also a link against a black background. In Netscape 7.1, the current background color is displayed as a horizontal bar below the image. This allows :hover effects that change the background color to have a visible effect, as this bar changes color. By default, it appears that the color is inherited from the body color, i.e. with no link style applied, the bar is black, and invisible against the background....
25
12938
by: Neal | last post by:
According to the CSS lint at http://htmlhelp.org/tools/csscheck/, "The shorthand background property is more widely supported than background-color." Can anyone point me to, or provide, information on what browsers have difficulty with the non-shortcut methods of setting background properties?
27
13571
by: Kevin Yu | last post by:
When I declare on HTML page <LINK href="mycss.css" type="text/css" rel=stylesheet /> .... <BODY class=myclass> in mycss.css BODY { FONT-WEIGHT: bold; FONT-SIZE: 12px; FONT-FAMILY: Arial, Geneva; background-image: url(images/back.jpg); }
11
109597
by: dgk | last post by:
Is there a way to change the foreground or background color of a single cell in an unbound datagridview?
4
2666
by: martin1 | last post by:
Hi, want to loop DataSet to change row background color based on data retrieved from sql db, the color can be blue, yellow, red or purple. Therefore, Is there any way (vb.net) to change dataset row background color? how to loop dataset, which is already populated data from database? Thanks
0
3248
by: owais_zahid | last post by:
hi guy! i m using visula studio 2005 and developing windows application. I came across a problem while setting the background color of "DataGridView" to transparent. Plz, help me on tht one.
0
1441
by: =?Utf-8?B?Y2FsZGVyYXJh?= | last post by:
Dear all, I have a datagridview whcih is bind to a database. I would like that the row backround color is red for all records where the content of the column x is 2. What is the way to do that ? thnaks for help regards
19
3979
by: david.karr | last post by:
If in my CSS I set the "background-color" property on the "body" element, it only covers the background of the elements defined in the body, up to the current width and height of the page. However, if the current component set has a resulting small height, this leaves most of the page with the original background color (white). However, if I set the property on the "html" element instead, it does color the entire visible page, beyond the...
0
8673
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
8601
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
9156
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...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7716
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
4365
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3043
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
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1998
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.