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.
Syncfusion Feedback

question about 2.0.5.1\Grid\Samples\DataBound\GridPerf

Thread ID:

Created:

Updated:

Platform:

Replies:

17528 Aug 11,2004 01:28 AM UTC Aug 11,2004 06:54 AM UTC Windows Forms 1
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On August 11, 2004 01:28 AM UTC

Hi Clay or anyone who may know the answer, In this sample, if I use virtualgridcontrol, DataTable as source, what would be the best way to color the single cell? The senarios would be like if in column c, any number larger than 30 will be in red, or if any number in column larger than 30, the column A cell at the same row will be in red. Of course, the data will come, go and update in real time. I could record the current location in the gridcontrol after calling update, then color it by location, but there must be a smarter way to do it. Any suggestions? Thanks a lot Chris

Administrator [Syncfusion]
Replied On August 11, 2004 06:54 AM UTC

You can use QueryCellInfo to set conditionally set the backcolors of cells. Here is code that will color columns 1 and 3 red if teh value in column 3 is larger than 30.
private void grid_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
	if(e.ColIndex > 0 && e.RowIndex > 0)
	{
		e.Style.CellValue = this.table.Rows[e.RowIndex-1][e.ColIndex-1];
		e.Handled = true;
		if(e.ColIndex == 3)
		{
			double d;
			if(double.TryParse(e.Style.Text, System.Globalization.NumberStyles.Any,
				null, out d) && d > 30)
			{
				e.Style.BackColor = Color.Red;
			}
		}
		else if(e.ColIndex == 1)
		{
			double d;
			if(double.TryParse(this.grid[e.RowIndex, 3].Text, 
				System.Globalization.NumberStyles.Any, 	null, out d) && d > 30)
			{
				e.Style.BackColor = Color.Red;
			}
		}
	}
}
One other thing, when you change teh value in column 3, you would want to make sure column 1 wa redrawn so it would reflect an y new color determined by the new value in column 3. You can do this in SaveCellInfo.
private void grid_SaveCellInfo(object sender, GridSaveCellInfoEventArgs e)
{
	if(e.ColIndex > 0 && e.RowIndex > 0)
	{
		this.table.Rows[e.RowIndex-1][e.ColIndex-1] = e.Style.CellValue;
		e.Handled = true;
		if(e.ColIndex == 3)
			this.grid.Invalidate(grid.RangeInfoToRectangle(GridRangeInfo.Cell(e.RowIndex, 1)));
	}
}

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.

Warning Icon 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.Close Icon

;