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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridRangeInfo

Thread ID:

Created:

Updated:

Platform:

Replies:

73730 May 15,2008 08:34 PM UTC May 17,2008 10:44 AM UTC WinForms 3
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On May 15, 2008 08:34 PM UTC

Hello,

I would like to change the background color of a cell whenever its numeric value becomes negative. To do this, I thought I'd use the GridControl.GridCellsChanged event and then iterate through the cells that have changed to determine whether they should have their background color updated. However, I can't figure how to perform this iteration using the GridRangeInfo object. Does anyone have a some sample code illustrating this or possibly even a better approach.

Thanks,
AP


Administrator [Syncfusion]
Replied On May 16, 2008 05:37 AM UTC

Hi AP,

Thanks for the interest in Syncfusion Grid.

You can handle QueryCellStyleInfo event and can change the backcolor of the cell if the value is a negative. You can check the CellValue of the CurrentCell and can set the backcolor if the CellValue is less than 0. Please refer the following code snippet that shows how we can handle QueryCellStyleInfo event to get the this behavior.


void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell
|| e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell)
{
if (e.TableCellIdentity.Column.MappingName == "B")
{
int cellvalue = Convert.ToInt32(e.Style.CellValue);
if (cellvalue < 0)
{
e.Style.BackColor = Color.Red;
//e.Style.Format = "{#,##}";// just a format
}
}
}
}


Please refer the sample in the below link that illustrates the above.

http://websamples.syncfusion.com/samples/Grid.Windows/F73730/main.htm

Please let me know if you have any questions.

Regards,
Asem.



Administrator [Syncfusion]
Replied On May 16, 2008 01:24 PM UTC

Hi Asem,

Thanks for your response. The problem is that I'm not using the GridGroupingControl. I'm using the regular GridControl object. There is no QueryCellStyleInfo event for that class.

>Hi AP,

Thanks for the interest in Syncfusion Grid.

You can handle QueryCellStyleInfo event and can change the backcolor of the cell if the value is a negative. You can check the CellValue of the CurrentCell and can set the backcolor if the CellValue is less than 0. Please refer the following code snippet that shows how we can handle QueryCellStyleInfo event to get the this behavior.


void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell
|| e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell)
{
if (e.TableCellIdentity.Column.MappingName == "B")
{
int cellvalue = Convert.ToInt32(e.Style.CellValue);
if (cellvalue < 0)
{
e.Style.BackColor = Color.Red;
//e.Style.Format = "{#,##}";// just a format
}
}
}
}


Please refer the sample in the below link that illustrates the above.

http://websamples.syncfusion.com/samples/Grid.Windows/F73730/main.htm

Please let me know if you have any questions.

Regards,
Asem.





Administrator [Syncfusion]
Replied On May 17, 2008 10:44 AM UTC

Hi AP,

You can handle QueryCellInfo for the GridControl. You can also use CurrentCellValidated event and can check if the value is

negative and change the backcolor of the cell. Please refer the following code snippet for more detail.


private void gridControl1_CurrentCellValidated(object sender, EventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
string s = cc.Renderer.ControlText;
int i = Convert.ToInt32(s);
if (i < 0)
{
this.gridControl1[cc.RowIndex, cc.ColIndex].BackColor = Color.Green;

}
}


Please refer sample in the below link that illustrates the above.

http://websamples.syncfusion.com/samples/Grid.Windows/73730B/main.htm

Please let me know if this not what you needed.

Regards,
Asem.



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

;