473,385 Members | 1,309 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,385 software developers and data experts.

Set the background colour of a grid

Hi
Is it possible to set the background colour of a grid
based on a value in data?
I guess that it is simple but I have been unable to figure
it out.

TIA
Nov 17 '05 #1
14 1232
What you want is the BackColor property on the DataGrid object. It takes a
Color enum
Color.Red for example

regards

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits/default.htm

"John Doe" <an*******@discussions.microsoft.com> wrote in message
news:0c****************************@phx.gbl...
Hi
Is it possible to set the background colour of a grid
based on a value in data?
I guess that it is simple but I have been unable to figure
it out.

TIA

Nov 17 '05 #2
What you want is the BackColor property on the DataGrid object. It takes a
Color enum
Color.Red for example

regards

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits/default.htm

"John Doe" <an*******@discussions.microsoft.com> wrote in message
news:0c****************************@phx.gbl...
Hi
Is it possible to set the background colour of a grid
based on a value in data?
I guess that it is simple but I have been unable to figure
it out.

TIA

Nov 17 '05 #3
Hi Alvin

I am just learning this, I have a grid that has a
DataTable as the source.

I have created the following function:
private void itemcreated(object sender,
DataGridItemEventArgs e)
{
if(((DataRowView).e.Item.DataItem).ItemArray[5].ToString
() == "0")
{
e.Item.Cells[5].BackColor = System.Drawing.Color.Red;
}
}

I have then specified that the datagrid should use this
function when OnItemCreated is fired.

This gives me an access violation that I guess is due to
the fact that I have a DataTable as the source. I think
that I am on the right track since removing the if
statement colors the column red as I want.

TIA
-----Original Message-----
What you want is the BackColor property on the DataGrid object. It takes aColor enum
Color.Red for example

regards

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits/default.htm

"John Doe" <an*******@discussions.microsoft.com> wrote in messagenews:0c****************************@phx.gbl...
Hi
Is it possible to set the background colour of a grid
based on a value in data?
I guess that it is simple but I have been unable to figure it out.

TIA

.

Nov 17 '05 #4
Hi Alvin

I am just learning this, I have a grid that has a
DataTable as the source.

I have created the following function:
private void itemcreated(object sender,
DataGridItemEventArgs e)
{
if(((DataRowView).e.Item.DataItem).ItemArray[5].ToString
() == "0")
{
e.Item.Cells[5].BackColor = System.Drawing.Color.Red;
}
}

I have then specified that the datagrid should use this
function when OnItemCreated is fired.

This gives me an access violation that I guess is due to
the fact that I have a DataTable as the source. I think
that I am on the right track since removing the if
statement colors the column red as I want.

TIA
-----Original Message-----
What you want is the BackColor property on the DataGrid object. It takes aColor enum
Color.Red for example

regards

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits/default.htm

"John Doe" <an*******@discussions.microsoft.com> wrote in messagenews:0c****************************@phx.gbl...
Hi
Is it possible to set the background colour of a grid
based on a value in data?
I guess that it is simple but I have been unable to figure it out.

TIA

.

Nov 17 '05 #5
Solved it myself. Used the following code:

private void Item_Bound(object sender,
DataGridItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.AlternatingItem))
{
if(e.Item.Cells[5].Text !="0")
{
e.Item.Cells[5].BackColor = System.Drawing.Color.Red;
}
}
}

Then I specified the following property on the datagrid
OnItemDataBound="Item_Bound"

-----Original Message-----
Hi Alvin

I am just learning this, I have a grid that has a
DataTable as the source.

I have created the following function:
private void itemcreated(object sender,
DataGridItemEventArgs e)
{
if(((DataRowView).e.Item.DataItem).ItemArray[5].ToString
() == "0")
{
e.Item.Cells[5].BackColor = System.Drawing.Color.Red;
}
}

I have then specified that the datagrid should use this
function when OnItemCreated is fired.

This gives me an access violation that I guess is due to
the fact that I have a DataTable as the source. I think
that I am on the right track since removing the if
statement colors the column red as I want.

TIA
-----Original Message-----
What you want is the BackColor property on the DataGridobject. It takes a
Color enum
Color.Red for example

regards

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits/default.htm

"John Doe" <an*******@discussions.microsoft.com> wrote inmessage
news:0c****************************@phx.gbl...
Hi
Is it possible to set the background colour of a grid
based on a value in data?
I guess that it is simple but I have been unable to

figure it out.

TIA

.

.

Nov 17 '05 #6
Solved it myself. Used the following code:

private void Item_Bound(object sender,
DataGridItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.AlternatingItem))
{
if(e.Item.Cells[5].Text !="0")
{
e.Item.Cells[5].BackColor = System.Drawing.Color.Red;
}
}
}

Then I specified the following property on the datagrid
OnItemDataBound="Item_Bound"

-----Original Message-----
Hi Alvin

I am just learning this, I have a grid that has a
DataTable as the source.

I have created the following function:
private void itemcreated(object sender,
DataGridItemEventArgs e)
{
if(((DataRowView).e.Item.DataItem).ItemArray[5].ToString
() == "0")
{
e.Item.Cells[5].BackColor = System.Drawing.Color.Red;
}
}

I have then specified that the datagrid should use this
function when OnItemCreated is fired.

This gives me an access violation that I guess is due to
the fact that I have a DataTable as the source. I think
that I am on the right track since removing the if
statement colors the column red as I want.

TIA
-----Original Message-----
What you want is the BackColor property on the DataGridobject. It takes a
Color enum
Color.Red for example

regards

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits/default.htm

"John Doe" <an*******@discussions.microsoft.com> wrote inmessage
news:0c****************************@phx.gbl...
Hi
Is it possible to set the background colour of a grid
based on a value in data?
I guess that it is simple but I have been unable to

figure it out.

TIA

.

.

Nov 17 '05 #7
substitute for the if part:
if(e.Item.Cells[5].Text = "0")
//color cell

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits/default.htm

"John Doe" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
Hi Alvin

I am just learning this, I have a grid that has a
DataTable as the source.

I have created the following function:
private void itemcreated(object sender,
DataGridItemEventArgs e)
{
if(((DataRowView).e.Item.DataItem).ItemArray[5].ToString
() == "0")
{
e.Item.Cells[5].BackColor = System.Drawing.Color.Red;
}
}

I have then specified that the datagrid should use this
function when OnItemCreated is fired.

This gives me an access violation that I guess is due to
the fact that I have a DataTable as the source. I think
that I am on the right track since removing the if
statement colors the column red as I want.

TIA
-----Original Message-----
What you want is the BackColor property on the DataGrid

object. It takes a
Color enum
Color.Red for example

regards

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits/default.htm

"John Doe" <an*******@discussions.microsoft.com> wrote in

message
news:0c****************************@phx.gbl...
Hi
Is it possible to set the background colour of a grid
based on a value in data?
I guess that it is simple but I have been unable to figure it out.

TIA

.

Nov 17 '05 #8
substitute for the if part:
if(e.Item.Cells[5].Text = "0")
//color cell

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits/default.htm

"John Doe" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
Hi Alvin

I am just learning this, I have a grid that has a
DataTable as the source.

I have created the following function:
private void itemcreated(object sender,
DataGridItemEventArgs e)
{
if(((DataRowView).e.Item.DataItem).ItemArray[5].ToString
() == "0")
{
e.Item.Cells[5].BackColor = System.Drawing.Color.Red;
}
}

I have then specified that the datagrid should use this
function when OnItemCreated is fired.

This gives me an access violation that I guess is due to
the fact that I have a DataTable as the source. I think
that I am on the right track since removing the if
statement colors the column red as I want.

TIA
-----Original Message-----
What you want is the BackColor property on the DataGrid

object. It takes a
Color enum
Color.Red for example

regards

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits/default.htm

"John Doe" <an*******@discussions.microsoft.com> wrote in

message
news:0c****************************@phx.gbl...
Hi
Is it possible to set the background colour of a grid
based on a value in data?
I guess that it is simple but I have been unable to figure it out.

TIA

.

Nov 17 '05 #9
Thanks Alvin
-----Original Message-----
substitute for the if part:
if(e.Item.Cells[5].Text = "0")
//color cell

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits/default.htm

"John Doe" <an*******@discussions.microsoft.com> wrote in messagenews:01****************************@phx.gbl...
Hi Alvin

I am just learning this, I have a grid that has a
DataTable as the source.

I have created the following function:
private void itemcreated(object sender,
DataGridItemEventArgs e)
{
if(((DataRowView).e.Item.DataItem).ItemArray [5].ToString () == "0")
{
e.Item.Cells[5].BackColor = System.Drawing.Color.Red; }
}

I have then specified that the datagrid should use this
function when OnItemCreated is fired.

This gives me an access violation that I guess is due to
the fact that I have a DataTable as the source. I think
that I am on the right track since removing the if
statement colors the column red as I want.

TIA
>-----Original Message-----
>What you want is the BackColor property on the DataGrid

object. It takes a
>Color enum
>Color.Red for example
>
>regards
>
>--
>
>
>-----------
>Got TidBits?
>Get it here: www.networkip.net/tidbits/default.htm
>
>"John Doe" <an*******@discussions.microsoft.com> wrote
in message
>news:0c****************************@phx.gbl...
>> Hi
>> Is it possible to set the background colour of a grid
>> based on a value in data?
>> I guess that it is simple but I have been unable to

figure
>> it out.
>>
>> TIA
>
>
>.
>

.

Nov 17 '05 #10
Thanks Alvin
-----Original Message-----
substitute for the if part:
if(e.Item.Cells[5].Text = "0")
//color cell

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits/default.htm

"John Doe" <an*******@discussions.microsoft.com> wrote in messagenews:01****************************@phx.gbl...
Hi Alvin

I am just learning this, I have a grid that has a
DataTable as the source.

I have created the following function:
private void itemcreated(object sender,
DataGridItemEventArgs e)
{
if(((DataRowView).e.Item.DataItem).ItemArray [5].ToString () == "0")
{
e.Item.Cells[5].BackColor = System.Drawing.Color.Red; }
}

I have then specified that the datagrid should use this
function when OnItemCreated is fired.

This gives me an access violation that I guess is due to
the fact that I have a DataTable as the source. I think
that I am on the right track since removing the if
statement colors the column red as I want.

TIA
>-----Original Message-----
>What you want is the BackColor property on the DataGrid

object. It takes a
>Color enum
>Color.Red for example
>
>regards
>
>--
>
>
>-----------
>Got TidBits?
>Get it here: www.networkip.net/tidbits/default.htm
>
>"John Doe" <an*******@discussions.microsoft.com> wrote
in message
>news:0c****************************@phx.gbl...
>> Hi
>> Is it possible to set the background colour of a grid
>> based on a value in data?
>> I guess that it is simple but I have been unable to

figure
>> it out.
>>
>> TIA
>
>
>.
>

.

Nov 17 '05 #11
Sorry for my silly question. But how do I loop through
each cell in the cells collection and set the background
colour.
Nov 17 '05 #12
Sorry for my silly question. But how do I loop through
each cell in the cells collection and set the background
colour.
Nov 17 '05 #13
for(int i = 0; i < e.item.cells.count;i++)
e.items.cells[i].BackColor = Color.red;
roughly

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"John Doe" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
Sorry for my silly question. But how do I loop through
each cell in the cells collection and set the background
colour.

Nov 17 '05 #14
for(int i = 0; i < e.item.cells.count;i++)
e.items.cells[i].BackColor = Color.red;
roughly

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"John Doe" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
Sorry for my silly question. But how do I loop through
each cell in the cells collection and set the background
colour.

Nov 17 '05 #15

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

Similar topics

4
by: Dj Frenzy | last post by:
Hi, I know how to use javascript to change a background image to another background image, and how to change a background colour to another background colour. Is there a way to change an image to a...
6
by: Louise | last post by:
Hi I have written an HTML pages which does not have any colour specifying tags as far I know. When I view this in an Microsoft internet explorer browser it appears with a white background and...
3
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
0
by: John Doe | last post by:
Hi Is it possible to set the background colour of a grid based on a value in data? I guess that it is simple but I have been unable to figure it out. TIA
7
by: PJ | last post by:
How can you set the background color of individual columns in a datagrid to be different to others? The table styles only allow you to do this at the grid level for all columns.
4
by: Lachlan Hunt | last post by:
Hi, I'm looking for an interoperable method of determining the current background colour of an element that is set using an external stylesheet. I've tried: elmt.style.backgroundColor; but...
10
by: Bob Bedford | last post by:
I've a table in wich I've this CSS: ..oddrow{background-color:#FFFFFF} ..evenrow{background-color:#CCCCCC} The oddrows are white and the even are grey. BUT ! when I do print the table,...
2
by: bissatch | last post by:
Hi, I am running a w3c CSS validation check on a site in development. I have many errors saying that my CSS is not valid because I have not defined the background-color but instead left it...
3
Frinavale
by: Frinavale | last post by:
Hi there, I'm using JavaScript to highlight a row or column in a table. I have created a CSS class that changes the background colour to a light blue and I apply this class to the cells in the...
1
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.