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

Change the Color of Rad Grid View column

4 Answers 1505 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sasmita
Top achievements
Rank 1
Sasmita asked on 09 Jul 2008, 02:27 AM
Hi All,
I have a grid. Based on some condition i want to change the color of one column.

I searched many articles. Every where i found i have to change each cell in that column. But is there any way i can directly set the column to some other.

Any kind of help is appreciated.

Sasmita

4 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 09 Jul 2008, 12:28 PM
Hi Sasmita,

You cannot directly set a BackColor to a column. As you may have read in other forums posts, you should subscribe to the CellFormatting event and then in the event handler set the BackColor of each CellElement which represents this column. Please refer to the following code snippet:
void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)     
{     
    if (e.CellElement.ColumnInfo is GridViewDataColumn)     
    {     
        if (((GridViewDataColumn)e.CellElement.ColumnInfo).FieldName == "City")     
        {     
            e.CellElement.DrawFill = true;     
            e.CellElement.NumberOfColors = 1;     
            e.CellElement.BackColor = System.Drawing.Color.Beige;     
        }     
    }     

Please note that you should set DrawFill to true in order to make the BackColor visible.

If you have additional questions, feel free to contact me.

All the best,
Nikolay
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Sasmita
Top achievements
Rank 1
answered on 09 Jul 2008, 07:06 PM
Thank you so much . Previous article was helpful...

Could you please help me in the below query mentioned.

In my page I have two grids. One master and one child. The child grid is being generated at run time and attached to the master grid.

I want to fire the CellFormatting and FilterChanged event of the child grid at run time.

My requirement is when any filtering condition is set for the child grid then that column of the child grid should be changed to blue color. So I want to fire the Filter change event of the child grid.

Though I have subscribed that event for the child grid , when I set any filtering condition on child grid , events are not getting fired.

For setting event for child grid I have done this at page_load event.

private void CreateChildEvents()

        {

            for (int i = 0; i < this.rgvBorrowSum.MasterGridViewTemplate.ChildGridViewTemplates.Count; i++)

            {

                this.rgvBorrowSum.MasterGridViewTemplate.ChildGridViewTemplates[i].FilterChanged += new FilterChangedEventHandler(ContractBrowser_FilterChanged);

            }

        }

Could you please help me out on this.

0
Nikolay
Telerik team
answered on 11 Jul 2008, 12:22 PM
Hello Sasmita,

Currently, the FilterChanging/FilterChanged events are not fired for GridViewTemplates. However, you can use the RadGridView.FilterChanged event and to identify the template where the filtering is applied.

Then, in the FilterChanged event handler you should call RadGridView.GridElement.Update method passing the GridUINotifyAction.StateChanged in order to fire the CellFormatting event.

I have attached a sample project which demonstrates the approach.

On a side note, I will ask you to review our License Developer policy on http://www.telerik.com/faq. Once you do it, please ask the purchase holder in your company to add you as a License Developer to the purchase. This will help us expedite your tickets.


Sincerely yours,
Nikolay
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Amir
Top achievements
Rank 1
answered on 14 Feb 2017, 04:00 AM
thank you
Tags
GridView
Asked by
Sasmita
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Sasmita
Top achievements
Rank 1
Amir
Top achievements
Rank 1
Share this question
or