473,586 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Color the User entered cell in Datagridview?

4 New Member
Hi All IT developer and C# expert please help me urgent.
I'm working on a project of Bakery Management. I'hd shown the room booked in hotel in Datagridveiw Control. My client require the cell color in different colors when he enters in particular cell. I had written code in dgv_Formatting Event for coloring but all cells of Datagriveiw are going to colored. I write code like follow.
private void dgv_CellFormatt ing(object sender, DataGridViewCel lFormattingEven tArgs e)
{

e.CellStyle.Bac kColor = Color.MediumPur ple;

}
Please help me urgent.
Dec 15 '09 #1
3 2515
KrishnaSarala
4 New Member
hi all it & c# expert help me
i want to color the cell of datagridview when user enters in particuler cell.
ihad write code like this.
private void dgv_CellFormatt ing(object sender, DataGridViewCel lFormattingEven tArgs e)
{

e.CellStyle.Bac kColor = Color.MediumPur ple;

}
but all the cells are going to coloured. please help me.
Dec 15 '09 #2
GaryTexmo
1,501 Recognized Expert Top Contributor
Maybe instead of the cell formatting event, try the cell value changed event?

I did up a quick example and it worked. Here's the appropriate snippets...

Expand|Select|Wrap|Line Numbers
  1.         public Form1()
  2.         {
  3.             ...
  4.             dataGridView1.CellValueChanged += new DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
  5.         }
  6.  
  7.         ...
  8.  
  9.         void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  10.         {
  11.             DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
  12.             row.Cells[e.ColumnIndex].Style.BackColor = Color.MediumPurple;
  13.         }
This worked for me... let me know how it works for you :) I'd imagine the access is relatively safe since the row and column index comes from the event, but you may want to put some bounds checking in there anyway.
Dec 15 '09 #3
tlhintoq
3,525 Recognized Expert Specialist
Please don't double-post your questions. It divides attempts to help you in an organized and cohesive manner. Your threads have been merged
Dec 15 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

13
9282
by: perplexed | last post by:
How do you convert a user inputted date to a unix timestamp before insterting it into your database? I have a form, with a textfield for a date that the user inputs in the format mm-dd-yyyy and three dropdow boxes for hours, minutes, and AM/PM. All of these need to be considered together and converted to one Unix Timestamp and then inserted...
0
1196
by: emer.kurbegovic | last post by:
I need to build a filter that will filter user entered html and which will allow only certain html tags through (i.e. <IMG>, <SCRIPTand <EMBEDwould be allowed). i was going to HtmlEncode the entire user html input and filter out only what is "allowed". i need the best way to filter for all possible known xss attacks. is there anything...
0
1065
by: tenko | last post by:
here's a question regarding changing units, say from g to kg without changing the entire codes.... my mathematical equation uses KG (kilograms), but the user can choose whether to enter values in G or KG. if the user entered the option in G, how can i convert from the string "KG" to "G" for every of the term in console.writeline that i do...
0
3450
by: =?Utf-8?B?QnJpYW5ESA==?= | last post by:
Hi I am trying to find a way to change the background color of a cell (flash or blink) when its value has changed (by user or data update). I need to be able to do this for more than one cell close to the same time. The code example below works however, while it is running if another cell is changed, it overrides it. DataGridViewRow row;...
4
4152
by: ghjk | last post by:
I want to compare user entered date with data base datetime value. Database value in datetime type and first i want to extract date part and then compare with user entered value. This is my query. Could someone tell me what is wrong with it? SELECT * FROM db WHERE Date = SELECT CAST(Date AS DATE) AS dateonly FROM db
2
1289
by: gilly1471 | last post by:
Yep, new to perl, I started yesterday, but am quickly excelling. I would just like to know how to use user entered data. Let's say I have a programm that calculates the circumference of a circle. The user has to enter in the radius of the circle and then the units of measurement. If the user enters his data into an html page that directs the...
1
944
by: mohanprasadgutta | last post by:
Hello everybody, I am facing problem in read color of a cell. problem description is as follows. for a particular cell by default colorindex = 35 is provided. but that cell is conditional formatted cell. The color of the cell will change based on the condition. later color of the cell is changed to color red (colorindex = 3) my intension is...
3
10532
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 selected row/column. It works great most of the time but sometimes the cell may have an inline style sets background colour to yellow. This, of...
3
1699
by: rhonda2010 | last post by:
My project consists of a user interface designed in Visual Studio 2010 Express. I have it linked to an Access database. At this time, I have two text boxes that the user will enter a number. I want to be able to write a query that will take the first and second number and pull the information from the database that is equal to or greater than...
0
7912
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...
0
7839
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...
0
8202
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. ...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
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...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.