473,799 Members | 3,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing the Color of a Row in a Datagrid

C# WinForms

I am trying to find a good solution for changing the color of a row in a
datagrid, at runtime, based on the contents of a certain cell of the row, or
a related value in the database. I cant believe it is as hard as I am
finding. This is surely a common problem.

All the solutions I have found so far though, seem very specific, and that
if I want this in various datagrids through my application I will have to
have a load of custom DataGridTextCol umns with Paint overrided.

I have a custom Datagrid object which has in it various custom methods and
properties that I want all my datagrids to have, so ideally I want to put
this row colour function in there, or in a similar high up object so I dont
have to keep creating custom column styles. Has anyone done anything like
this before or does everyone just keep overriding the column style??

Thanks

Ste
Apr 20 '06 #1
1 1509

One more thing. I see that in WebForms you can hook into the row through
the ItemDataBound event. Is there not an equivalent entry point for
WinForms??

"Steve" wrote:
C# WinForms

I am trying to find a good solution for changing the color of a row in a
datagrid, at runtime, based on the contents of a certain cell of the row, or
a related value in the database. I cant believe it is as hard as I am
finding. This is surely a common problem.

All the solutions I have found so far though, seem very specific, and that
if I want this in various datagrids through my application I will have to
have a load of custom DataGridTextCol umns with Paint overrided.

I have a custom Datagrid object which has in it various custom methods and
properties that I want all my datagrids to have, so ideally I want to put
this row colour function in there, or in a similar high up object so I dont
have to keep creating custom column styles. Has anyone done anything like
this before or does everyone just keep overriding the column style??

Thanks

Ste

Apr 20 '06 #2

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

Similar topics

3
3183
by: mvargasp | last post by:
Hi all, I have a web form which contains a frame, (a form containing a menu on the left and a web form containing a datagrid on the right). Also there is a button (right side) which transforms the datagrid content in a CSV file and forces the user to download the file. The following is the code used to force a download: 'strCadena contains the datagrid info separated by commas,
1
3261
by: Amos | last post by:
Can I add a column to the datagrid and also resize it? I add them like this: DataTableAddress.Columns.Add("Col1", typeof(string)); DataTableAddress.Columns.Add("Col2", typeof(string)); DataTableAddress.Columns.Add("Col3", typeof(string)); I'd like to add to resize them without using a datacolumn because there's over 30 columns and because the application is working well already (I don't know how the datacolumn additions will affect the...
1
1980
by: Shawn Benson | last post by:
I have a Windows form where a user enters an order number which returns a dataset that is bound to a datagrid. The problem is when a user clicks on a cell in the datagrid, then enters another order to get information for, everything is updated with the new data except the cell in the grid that was selected. This behavior does not occur when a table style is not applied to the datagrid. How do I refresh the datagrid so that the cell in...
3
3003
by: Doug | last post by:
Hi I have the following code (not mine) that populates a datagrid with some file names. But I want to replace the datagrid with a combo box. private void OnCurrentDataCellChanged(object sender, System.EventArgs e) {try{ DataSet ds = dgMembers.DataSource as DataSet;
1
1210
by: Simon Harris | last post by:
Hi All, Ok, I have 6 datagrids, populated from 1 dataset. Each datagrid has 3 columns. There are 18 columns in the dataset. I have written a sub to change the background colour of the row in the datagrid, if the current rows 'booked' column value = 'yes' Here is my code:
2
2124
by: david | last post by:
Problem: There is a search button, Search, in form, for searching patient info list. The error occurs after the following steps: 1. search first time is OK, and all found the records are displayed in the datagrid by using databind(). 2. After the first-time search, I navigate the pages by clicking the page changing arrow < or > which defined in datagrid design (of course, the page index is chaning). 3. After the the page index changed,...
1
1822
by: Anup | last post by:
Hi group, I m using protected System.Web.UI.WebControls.DataGrid (ASP.NET 1.x) I have set the "pager style mode" to "NumericPages" with "AllowingPaging=true"
1
2062
by: Veeves | last post by:
I would like to change the width of a datagrid column at run time. I have noticed when creating a datagrid, if the header text is shorter than the data in the column, then the column width set by the framework is only wide enough to accomodate the data. The data is packed so closly together it is hard to read. I have tried changing this in the dg_itemdatabound event but ran into a problem. The e.Item.Cells(1).Width property is in...
1
1869
by: Blasting Cap | last post by:
I am having trouble changing the font for a PushButton control in a datagrid button column. I have seen several posts refer to styles and simple changes to the HTML for font changes but most of those referred to a LinkButton type of control. But in cases where someone is using the PushButton there are no posted solutions. Whenever these changes are made to the PushButton control they do not make any requested changes. I have seen one...
0
9546
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10491
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10268
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10031
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7571
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.