This is a migrated thread and some comments may be shown as answers.

Change ForeColor on Individual Cells in RowFormatting Event

2 Answers 98 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tom Uellner
Top achievements
Rank 1
Tom Uellner asked on 08 May 2012, 03:55 AM
I have a client request to hide the first 7 columns of a grid if they are the same values as the columns above. I have the logic to check and match the previous row but I can't find a way to iterate through the cells in RowInfo.

I was planning on setting the ForeColor to the BackColor to hide it from the user but keep the value so I can sort correctly. Any suggestions would be greatly appreciated.

Thanks,
Tom

        void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
        {
            GridViewRowInfo row = e.RowElement.RowInfo;

            if (row.ViewTemplate != this.gridDashboard.MasterTemplate)
            {
                return;
            }

            if (lastRow == null)
            {
                lastRow = row;
                return;
            }

            // Does the current row match the last row?
            if (lastRow != null && lastRow != row)
            {
                bool isMatch = true;
                for (int i = 0; i < 8; i++)
                {
                    if (!Object.Equals( row.Cells[i].Value,  lastRow.Cells[i].Value))
                    {
                        isMatch = false;
                    }
                }

                if (isMatch)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        // Clear the duplicate cells
                        // by setting ForeColor = BackColor
                    }
                }
                else
                {
                    lastRow = row;
                }
            }
        }


2 Answers, 1 is accepted

Sort by
0
Accepted
Boryana
Telerik team
answered on 10 May 2012, 05:07 PM
Hello Tom,

Thank you for writing.

You can use the CurrentRowChanged event to track whether the rows have the same cell values and set the Tag property of the RowInfo. Further, you can style the cells depending on the Tag value in the CellFormatting event handler. For implementation details please refer to the attached sample project.

Off topic, I noticed that your subscription has expired, which means that your support package has exipred as well. Note that you will need to renew your subscription in order to continue to receive support from us. To do this, please contact sales@telerik.com or check your account (www.telerik.com/account.aspx). 

I hope you find my answer helpful. Let me know if you have further queries.

Kind regards,
Boryana
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Tom Uellner
Top achievements
Rank 1
answered on 10 May 2012, 10:42 PM
Thank you Boryana for your help. I'm sure this will get me where I need to be.

-Tom
Tags
GridView
Asked by
Tom Uellner
Top achievements
Rank 1
Answers by
Boryana
Telerik team
Tom Uellner
Top achievements
Rank 1
Share this question
or