Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Conditional Format for rows? (Read 3620 times)
mustafa
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Aug 3rd, 2010
Conditional Format for rows?
Jul 31st, 2014 at 12:23pm
Print Post  
Hello,

MindFusion ConditionalFormats demo shows how to set fill color of cell if its value is in specified condition. Is there any way to fill red full row length if any one cell in the row is in the condition (< 0 for my project)?

Best Regards,
Mustafa Koç
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Conditional Format for rows?
Reply #1 - Jul 31st, 2014 at 2:12pm
Print Post  
Hi,

This is not possible out of the box, but can be achieved manually by using the following method:

Code
Select All
private void ApplyFormatting(Worksheet sheet, int fromRow, int toRow)
{
	var rows = sheet.Cells.Where(cell => cell.Row >= fromRow && cell.Row <= toRow).GroupBy(cell => cell.Row);
	foreach (var row in rows)
	{
		int rowIndex = row.Key;
		bool met = false;
		foreach (var cell in row)
		{
			if (cell.Value is double)
			{
				if ((double)cell.Value < 0)
				{
					met = true;
					break;
				}
			}
		}

		if (met)
			sheet.Rows[rowIndex].Style.Background = new MindFusion.Drawing.SolidBrush(Color.Red);
		else
			sheet.Rows[rowIndex].Style.Background = null;
	}
} 


The method inspects the cells in the specified rows and applies the appropriate background to the entire row. You can initially call this method for all rows in the worksheet. Then you can listen to the Worksheet.CellChanged event and call the method only for the affected row:

Code
Select All
activeSheet.CellChanged += (s, e) =>
{
	ApplyFormatting(e.Cell.Worksheet, e.Cell.Row, e.Cell.Row);
}; 


However, this event is not raised when the value of a cell is changed indirectly, for example, as a result of a formula reevaluation. If you have formulas in the worksheet, you may need to update all rows again.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint