473,320 Members | 2,180 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,320 software developers and data experts.

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 24747
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).BackColor = Drawing.Color.Yellow
Case "Brazil" : GridView1.Rows(CountR).BackColor = Drawing.Color.Violet
Case "Belgium" : GridView1.Rows(CountR).BackColor = Drawing.Color.Aqua
Case Else : GridView1.Rows(CountR).BackColor = Drawing.Color.Coral
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).BackColor = Drawing.Color.Yellow
Case "Brazil" : GridView1.Rows(CountR).BackColor = Drawing.Color.Violet
Case "Belgium" : GridView1.Rows(CountR).BackColor = Drawing.Color.Aqua
Case Else : GridView1.Rows(CountR).BackColor = Drawing.Color.Coral
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).BackColor = Drawing.Color.Yellow
Case "Brazil" : GridView1.Rows(CountR).BackColor = Drawing.Color.Violet
Case "Belgium" : GridView1.Rows(CountR).BackColor = Drawing.Color.Aqua
Case Else : GridView1.Rows(CountR).BackColor = Drawing.Color.Coral
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(Column_Name).ColumnMapping() = MappingType.Hidden

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).BackColor = Drawing.Color.Yellow
Case "Brazil" : GridView1.Rows(CountR).BackColor = Drawing.Color.Violet
Case "Belgium" : GridView1.Rows(CountR).BackColor = Drawing.Color.Aqua
Case Else : GridView1.Rows(CountR).BackColor = Drawing.Color.Coral
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(Column_Name).ColumnMapping() = MappingType.Hidden

B.

Jun 27 '06 #5
I figure now

DataGridView.Columns(colume_name).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).BackColor = Drawing.Color.Yellow
> Case "Brazil" : GridView1.Rows(CountR).BackColor = Drawing.Color.Violet
> Case "Belgium" : GridView1.Rows(CountR).BackColor = Drawing.Color.Aqua
> Case Else : GridView1.Rows(CountR).BackColor = Drawing.Color.Coral
> 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(Column_Name).ColumnMapping() = MappingType.Hidden

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).BackColor = Drawing.Color.Yellow
> Case "Brazil" : GridView1.Rows(CountR).BackColor = Drawing.Color.Violet
> Case "Belgium" : GridView1.Rows(CountR).BackColor = Drawing.Color.Aqua
> Case Else : GridView1.Rows(CountR).BackColor = Drawing.Color.Coral
> 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(Column_Name).ColumnMapping() = MappingType.Hidden

B.


Then go up first. :)

MyDataGridView.DataSource.Table.Columns(Column_Nam e).ColumnMapping() =
MappingType.Hidden

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(MyDataGridView.DataSource,
DataView).Table.Columns(Column_Name).ColumnMapping () =
MappingType.Hidden
B.

Jun 28 '06 #7

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

Similar topics

5
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...
25
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...
27
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:...
11
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
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...
0
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
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...
19
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,...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.