We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

DataGridColoredTextBoxColumn and DataGrid Sorting

Thread ID:

Created:

Updated:

Platform:

Replies:

2344 Jan 9,2003 08:43 AM Feb 25,2004 12:52 PM Windows Forms 4
loading
Tags: FAQ
Tim Keogh
Asked On January 9, 2003 08:43 AM

I've got a datagrid with RED, BLACK, and GREEN cells for % changes. (Thanks for the FAQ on this). But my datagrid is sortable and the colors of the textboxes are fixed. Can anyone suggest a solution ? Tim

Oussax
Replied On January 12, 2003 04:47 AM

This may help you: when creating your datagrid columns, let them inherit from this class and not from the DataGridTextBoxcolumn. Now this code will go and check the data of the datagrid cell on the row selected and in my case on the column 1. You should chose the percentage column in your case. Then a check is going to be made on the value of the cell chosen: In my case i have 2 choices In your case you should make the switch on the percentage value entered in the cell. let the cases be of the type : 0 < value < 10 ..... 10 <= value < 20 .......... Automaticaly the colors of all the row cells will change to the color selected. I hope that this will help you. If you have any questions just mail me Moussa.Azar@ifsal.com public class DataGridColoredTextBoxColumn : DataGridTextBoxColumn { TransDetail trans; public DataGridColoredTextBoxColumn(TransDetail TransTemp) { trans = TransTemp; } protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight) { // the idea is to conditionally set the foreBrush and/or backbrush // depending upon some crireria on the cell value try { if (rowNum != trans.dtgTrans.CurrentRowIndex) { DataGridCell cell = new DataGridCell(rowNum,1); // Saves the value of the cell into a string string c = trans.dtgTrans[cell].ToString(); // Checks the value of that string with the 2 options switch(c) { case "Payment": { backBrush = new SolidBrush(Color.Beige); foreBrush = new SolidBrush(Color.Brown); break; } case "Bill": { backBrush = new SolidBrush(Color.LightGray); foreBrush = new SolidBrush(Color.Gray); break; } } } } catch { // Do nothing } finally { // make sure the base class gets called to do the drawing with // the possibly changed brushes base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight); } } }

Jen Wardwell
Replied On January 2, 2004 02:41 PM

I am having this problem too. I was going to try your code but I couldn't figure out what transDetail variable is supposed to be. Any help?

Milind
Replied On February 5, 2004 12:08 PM

Has anyone figured out what the TransDetail object is all about ? > I've got a datagrid with RED, BLACK, and GREEN cells for % changes. (Thanks for the FAQ on this). > > But my datagrid is sortable and the colors of the textboxes are fixed. > > Can anyone suggest a solution ? > > Tim

Administrator [Syncfusion]
Replied On February 25, 2004 12:52 PM

> This may help you: > when creating your datagrid columns, let them inherit from this class and not from the DataGridTextBoxcolumn. > Now this code will go and check the data of the datagrid cell on the row selected and in my case on the column 1. > You should chose the percentage column in your case. > > Then a check is going to be made on the value of the cell chosen: In my case i have 2 choices > In your case you should make the switch on the percentage value entered in the cell. > let the cases be of the type : 0 < value < 10 ..... 10 <= value < 20 .......... > > Automaticaly the colors of all the row cells will change to the color selected. > > > I hope that this will help you. If you have any questions just mail me Moussa.Azar@ifsal.com > > > > public class DataGridColoredTextBoxColumn : DataGridTextBoxColumn > { > TransDetail trans; > > public DataGridColoredTextBoxColumn(TransDetail TransTemp) > { > trans = TransTemp; > } > > protected override void Paint(System.Drawing.Graphics g, > System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager > source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush > foreBrush, bool alignToRight) > { > // the idea is to conditionally set the foreBrush and/or backbrush > // depending upon some crireria on the cell value > try > { > if (rowNum != trans.dtgTrans.CurrentRowIndex) > { > DataGridCell cell = new DataGridCell(rowNum,1); > // Saves the value of the cell into a string > string c = trans.dtgTrans[cell].ToString(); > > // Checks the value of that string with the 2 options > switch(c) > { > case "Payment": > { > backBrush = new SolidBrush(Color.Beige); > foreBrush = new SolidBrush(Color.Brown); > break; > } > case "Bill": > { > backBrush = new SolidBrush(Color.LightGray); > foreBrush = new SolidBrush(Color.Gray); > break; > } > } > } > } > catch > { > // Do nothing > } > finally > { > // make sure the base class gets called to do the drawing with > // the possibly changed brushes > base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight); > } > } > }

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;