UltraGrid changes color based on the background of the conditional cell.

Source: Internet
Author: User
Code
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Linq;
Using System. Text;
Using System. Windows. Forms;
Using Infragistics. Win;
Using Infragistics. Win. UltraWinGrid;

Namespace WindowsDataGrid
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}

Private void Form1_Load (object sender, EventArgs e)
{
DataTable dataTable = new DataTable ();
DataTable. Columns. Add ("GPNO", typeof (string ));
DataTable. Columns. Add ("Price", typeof (float ));
DataTable. Columns. Add ("Price2", typeof (float ));

DataTable. Rows. Add (new object [] {"54545", 1.02,-2.32 });
DataTable. Rows. Add (new object [] {"54522",-2.02, 1.2 });
DataTable. Rows. Add (new object [] {"54511", 3.02,-1.12 });
DataTable. Rows. Add (new object [] {"54512", 1.02,-2.32 });
DataTable. Rows. Add (new object [] {"54514",-2.02, 1.2 });
DataTable. Rows. Add (new object [] {"54513", 3.02,-1.12 });

Ultrabod1.datasource = able;
Ultrabod1.databind ();


}

Private void ultrabod=initializelayout (object sender, Infragistics. Win. UltraWinGrid. InitializeLayoutEventArgs e)
{

Ultrabodlayout layout = e. Layout;
Ultra'dband rootBand = layout. Bands [0];
Ultrabodoverride rootOverride = layout. Override;

RootBand. Columns ["Price"]. ValueBasedAppearance = CreateOperatorConditionValueAppearance (0 );
RootBand. Columns ["Price2"]. ValueBasedAppearance = CreateOperatorConditionValueAppearance (0 );
}

# Region CreateOperatorConditionValueAppearance
/// <Summary>
/// The cell dynamically changes color based on the data value
/// </Summary>
/// <Param name = "num"> </param>
/// <Returns> </returns>
Private ConditionValueAppearance CreateOperatorConditionValueAppearance (float num)
{
ConditionValueAppearance conditionValueAppearance = new ConditionValueAppearance ();
OperatorCondition negativeCondition = new OperatorCondition (ConditionOperator. LessThan, num );
Infragistics. Win. Appearance negativeAppearance = new Infragistics. Win. Appearance ("Negative ");
NegativeAppearance. ForeColor = Color. Green;
OperatorCondition positiveCondition = new OperatorCondition (ConditionOperator. greaterthanorcondito, num );
Infragistics. Win. Appearance positiveAppearance = new Infragistics. Win. Appearance ("Positive ");
PositiveAppearance. ForeColor = Color. Red;
ConditionValueAppearance. Add (negativeCondition, negativeAppearance );
ConditionValueAppearance. Add (positiveCondition, positiveAppearance );
Return conditionValueAppearance;
}
# Endregion CreateOperatorConditionValueAppearance
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.