Link to home
Start Free TrialLog in
Avatar of Jayesh Acharya
Jayesh AcharyaFlag for United States of America

asked on

cell fromtating of DataGridView need to compare two values from two cells same row, c#

I have a win form that has a gridview, and I need to change the color of the cell, based on itslef and a different cell.
If you look at the code below it works fine when changign the color of the cell besad on the current cells value.
But I need to be able to compare both values and then change the cell color.

The position of the colums can change but not the name.

        private void ECCN_CellFormatting(DataGridViewCellFormattingEventArgs ee, string case_str)
        {

            switch (case_str)
            {
                case "Y": ee.CellStyle.BackColor = Color.LawnGreen; break;
                case "N": ee.CellStyle.BackColor = Color.Red; break;
                case "0": ee.CellStyle.BackColor = Color.Red; ee.CellStyle.ForeColor = Color.Yellow; break;
                default: break;
            }
        }

        private void dataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs ee)
        {

            switch (dataGridView1.Columns[ee.ColumnIndex].Name)
            {
                case "eccn_available": ECCN_CellFormatting(ee, (string)ee.Value); break;
                case "eccn_value": ECCN_CellFormatting(ee, (string)ee.Value); break;
                default: break;
            }
        }


these methods are called by :
        public void InitializeGrid(DataGridView lv_StockCheckdataGridView
                                  ,string GridViewName)
        {

 
            lv_StockCheckdataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            lv_StockCheckdataGridView.ContextMenuStrip = this.contextMenuStrip1;
            lv_StockCheckdataGridView.AllowUserToAddRows = false;
            lv_StockCheckdataGridView.AllowUserToDeleteRows = false;
            lv_StockCheckdataGridView.AllowUserToOrderColumns = true;
            lv_StockCheckdataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            lv_StockCheckdataGridView.Size = new System.Drawing.Size(1074, 604);
            lv_StockCheckdataGridView.TabIndex = 5;
            lv_StockCheckdataGridView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dataGridView1_MouseDown);
            lv_StockCheckdataGridView.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.dataGridView_CellFormatting);
            lv_StockCheckdataGridView.Location = new System.Drawing.Point(12, 43);
            lv_StockCheckdataGridView.Name = GridViewName;
            lv_StockCheckdataGridView.ReadOnly = true;
            lv_StockCheckdataGridView.AllowUserToResizeColumns = true;

        }


I need a way to look at all the values for the rows I have just populated in the grid and
ASKER CERTIFIED SOLUTION
Avatar of Sudhakar Pulivarthi
Sudhakar Pulivarthi
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jayesh Acharya

ASKER

I have been pulled away from this project at the moment, so I can confirm the result from the solution, but I am going to give you the points and assume for now that the solution works, thanks Jay