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

How to Color the User entered cell in Datagridview?

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_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{

e.CellStyle.BackColor = Color.MediumPurple;

}
Please help me urgent.
Dec 15 '09 #1
3 2507
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_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{

e.CellStyle.BackColor = Color.MediumPurple;

}
but all the cells are going to coloured. please help me.
Dec 15 '09 #2
GaryTexmo
1,501 Expert 1GB
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 Expert 2GB
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
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...
0
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...
0
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...
0
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...
4
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....
2
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....
1
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...
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...
3
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...
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?
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
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,...
0
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,...
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.