Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
620
Color of the specific rows not changing.
posted

I am trying to change the color of the rows whose ID is less than 5. But this is not working. I am trying to use the NorthWind Dataset. Can anyone help in finding the problem.

 

Here is the code:

namespace Sample_UltraGrid

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)

        {

            this.ordersTableAdapter.Fill(this.nwindDataSet.Orders);

        }

        private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)

        {

            // Create an appearance for values which are less than 5

            Infragistics.Win.Appearance lessThan = e.Layout.Appearances.Add("Less");

            lessThan.ForeColor = Color.Red;

            // Create an appearance for values which are greater than 5

            Infragistics.Win.Appearance greaterThan = e.Layout.Appearances.Add("Greater");

            greaterThan.ForeColor = Color.Green;

        }

        private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)

        {

            UltraGrid grid = (UltraGrid)sender;

            // Get the value of the EmployeeID column.

            UltraGridColumn employeeIDColumn = this.ultraGrid1.DisplayLayout.Bands[0].Columns["EmployeeID"];

            int ID = (int)e.Row.GetCellValue(employeeIDColumn);

            if (ID < 5)

                // Use the Negative Appearance already defined in the grid's Appearances collection.

                e.Row.Cells["EmployeeID"].Appearance = grid.DisplayLayout.Appearances["Less"];

            else

                // Use the Positive Appearance already defined in the grid's Appearances collection.

                e.Row.Cells["EmployeeID"].Appearance = grid.DisplayLayout.Appearances["Greater"];

        } 

    }

}