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. Image for the cookie policy date

Customize Style.Borders.Bottom

Hi, I used GridGroupingControl 3.2.1.0. I want to customize the bottom border of cells depends on some columns value of the previous rows. Sample : 3 columns : - Col1 string - Col2 double - Col3 double Col1 Col2 Col3 Row 1 10 0 Row 2 0 10 --------------------- Row 3 10 0 Row 4 10 0 Row 5 0 20 --------------------- When (Total(Col2) - Total(Col3) == 0), i want to have a bottom border line on the cells ( Style.Borders.Bottom = new GridBorder(GridBorderStyle.Solid, Color.Red)) How can i do this ? Regards, Mikaël

4 Replies

AD Administrator Syncfusion Team June 21, 2005 06:02 AM

In general, to set conditional cell specific properties, you use the grid.QueryCellStyleInfo event. In your event code, if e.TableCellIdentity points to a cell where you may want to change the e.Style settings, then you would test whatever condition you are using for that particular cell, and if it is true, then change e.Style accordingly. Exactly how you go about testing things things depends upon exactly what you want to test. In your case you are using the difference to two totals, how/what are you totalings? Is it the whole column, or just a few rows in the columns or a grouped set of rows or ??. Are you trying to use a SummaryRow to do these totals, or something else? If you can upload a little sample project showing what you are doing, and explain exactly when you want a red border, maybe we can modify your sample to do this.


MM Mikaël Morvan June 22, 2005 04:06 AM

This sample (WindowsApplication8_4509.zip) show what i want doing. The 2nd gridGroupingControl show the result i want to obtain by the 1st gridGroupingControl, which used event or another method to set conditionaly the red border of rows.


AD Administrator Syncfusion Team June 22, 2005 06:29 AM

Try this code.
private void gridGroupingControl1_TableControlPrepareViewStyleInfo(object sender, GridTableControlPrepareViewStyleInfoEventArgs e)
{
	if ((e.Inner.ColIndex == 2) || (e.Inner.ColIndex == 3))
	{
		if (e.Inner.Style.Text == "0")
			e.Inner.Style.Text = "";
	}
	GridTableCellStyleInfo style = e.TableControl.Model[e.Inner.RowIndex, e.Inner.ColIndex];
	if(SumMatches(style))
		e.Inner.Style.Borders.Bottom = new GridBorder(GridBorderStyle.Solid, Color.Red);
}
private bool SumMatches(GridTableCellStyleInfo style)
{
	if(style.TableCellIdentity.TableCellType != GridTableCellType.RecordFieldCell
		&& style.TableCellIdentity.TableCellType != GridTableCellType.AlternateRecordFieldCell
		|| (style.TableCellIdentity.DisplayElement.ParentRecord == null))
		return false;
	GridRecord rec = style.TableCellIdentity.DisplayElement.ParentRecord as GridRecord;
	int index = this.gridGroupingControl1.Table.FilteredRecords.IndexOf(rec);
	double sum1 = 0;
	double sum2 = 0;
	for(int i = 0; i <= index; ++i)
	{
		Record r = this.gridGroupingControl1.Table.FilteredRecords[i];
		sum1 += (double) r.GetValue("Value1");
		sum2 += (double) r.GetValue("Value2");
		
	}
	return (Math.Abs(sum1 - sum2) < 1e-7);
}


MM Mikaël Morvan June 22, 2005 09:41 AM

Thanks, it was exactly what i want.

Loader.
Live Chat Icon For mobile
Up arrow icon