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

Setting the BackColor of indvidual cells in a DataGridView

Hello All,

I have been trying to figure out how to set the BackColor of
individual cells in a DataGridView. I found the following solution in
a VB usenet group
>>>>>
DataGridView1.Item(ColumnIndex, RowIndex).Style.BackColor = Color
DataGridView1.Item(ColumnIndex, RowIndex).Style.ForeColor = Color

or

DataGridView1.CurrentCell.Style.BackColor = Color
DataGridView1.CurrentCell.Style.ForeColor = Color
>>>>>
I figured I could just change the () to [] and it would work in C#.
Howver, the DataGridView does not seem to have an Item property. How
can I accomplish this using C#?

Thanks,

Paul

Feb 9 '07 #1
4 31976
The syntax is to use the indexer directly on the DataGridView and not
on an Items property.

Me.DataGridView1(2, 3).Style.BackColor = Color.Red

================
Clay Burch
Syncfusion, Inc.

Feb 10 '07 #2
The C# syntax is

this.dataGridView1[2,3].Style.BackColor = Color.Red;

===============
Clay Burch
Syncfusion, Inc.

Feb 10 '07 #3
You have to do it through the DefaultCellStyle property.

DataGridViewCellStyle MakeItRed = new DataGridViewCellStyle;
MakeItRed.BackColor = Color.Red;

//make a whole column red
myGrid.Columns(1).DefaultCellStyle = MakeItRed;

//make a specific cell red
DataGridViewRow row2 = myGrid.Rows(2);
row2.Cells(2).Style = MakeItRed

Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
-----------------------------------------------
"Paul" <he********@yahoo.cawrote in message
news:11**********************@a34g2000cwb.googlegr oups.com...
Hello All,

I have been trying to figure out how to set the BackColor of
individual cells in a DataGridView. I found the following solution in
a VB usenet group
>>>>>>
DataGridView1.Item(ColumnIndex, RowIndex).Style.BackColor = Color
DataGridView1.Item(ColumnIndex, RowIndex).Style.ForeColor = Color

or

DataGridView1.CurrentCell.Style.BackColor = Color
DataGridView1.CurrentCell.Style.ForeColor = Color
>>>>>>

I figured I could just change the () to [] and it would work in C#.
Howver, the DataGridView does not seem to have an Item property. How
can I accomplish this using C#?

Thanks,

Paul

Feb 10 '07 #4
Actually, I should have said, "You *can* do it through the DefaultCellStyle
property".

Robin S.
--------------------------
"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:RN******************************@comcast.com. ..
You have to do it through the DefaultCellStyle property.

DataGridViewCellStyle MakeItRed = new DataGridViewCellStyle;
MakeItRed.BackColor = Color.Red;

//make a whole column red
myGrid.Columns(1).DefaultCellStyle = MakeItRed;

//make a specific cell red
DataGridViewRow row2 = myGrid.Rows(2);
row2.Cells(2).Style = MakeItRed

Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
-----------------------------------------------
"Paul" <he********@yahoo.cawrote in message
news:11**********************@a34g2000cwb.googlegr oups.com...
>Hello All,

I have been trying to figure out how to set the BackColor of
individual cells in a DataGridView. I found the following solution in
a VB usenet group
>>>>>>>
DataGridView1.Item(ColumnIndex, RowIndex).Style.BackColor = Color
DataGridView1.Item(ColumnIndex, RowIndex).Style.ForeColor = Color

or

DataGridView1.CurrentCell.Style.BackColor = Color
DataGridView1.CurrentCell.Style.ForeColor = Color
>>>>>>>

I figured I could just change the () to [] and it would work in C#.
Howver, the DataGridView does not seem to have an Item property. How
can I accomplish this using C#?

Thanks,

Paul


Feb 10 '07 #5

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

Similar topics

10
by: michael sorens | last post by:
Is it possible to store an unbound DataGridView component into a setting? I naively tried defining a Setting that is a DataGridView called DGV, then simply assigning it:...
0
by: Mike P | last post by:
I have a number of colours in a database linked to different conditions, and this data is displayed in a gridview. I want to set the BackColor of a gridview cell dependent upon this value, for...
1
by: sklett | last post by:
I've got a strange situation here. I have a databound DataGridView that also has un-bound columns. When the view loads, I want to update the values of the unbound columns. If I attempt to modify...
0
by: Rick | last post by:
I can't find an application setting property for the DataGridView.AlternatingRowsDefaultCellStyle.BackColor. Am I missing something, or did MS just not add this option? I know how to do this...
0
by: Steve | last post by:
Hi All I am using VB.net 2005 professional I set the background color of a datagridview cell to different colors depending on many reasons I set them in the cellformatting event and all...
1
by: Steve | last post by:
Hi All I am using VB.net 2005 professional I set the background color of a datagridview cell to different colors depending on many reasons I set them in the cellformatting event and all...
5
by: davidson1 | last post by:
Hai Friends, I have the following code for Dynamically Created Tables, I have created the panel in the webform....... Dim tab5 As New Table Dim row1 As New TableRow Dim cell1 As...
1
by: ravitunk | last post by:
hello..am developing a windows application which has a datagridview control with many columns.......i have a problem with changing the backcolor of a particular cell based on a specific...
7
by: bobk | last post by:
My apologies upfront for what I am sure is a newbie question, but I have been unable to find an answer via search. I am a VB6 programmer trying to write programs in VB 2008 Express. I have an...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.