- Welcome, Guest. Please Login or Register
  We are soon releasing MindFusion.JavaScript pack. Initial version includes chart, diagram, calendar, map, virtual keyboard, gauge and UI components. Here are the beta version and live demo for anyone interested.  
Page Index Toggle Pages: 1 Send Topic Print  
Conditional Format for rows?
Read 2088 times

mustafa   Offline
YaBB Newbies
Posts: 8
I love YaBB 1G - SP1!

Conditional Format for rows?
Jul 31st, 2014 at 1:23pm

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ç
IP Logged    

Meppy   Offline
YaBB Moderator
Posts: 1783
Gender: male
MindFusion support

Re: Conditional Format for rows?
Reply #1 - Jul 31st, 2014 at 3:12pm

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

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;

		if (met)
			sheet.Rows[rowIndex].Style.Background = new MindFusion.Drawing.SolidBrush(Color.Red);
			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:

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.

IP Logged    
Page Index Toggle Pages: 1 Send Topic Print