Change the Color of Rad Grid View column

5 posts, 0 answers
  1. Sasmita
    Sasmita avatar
    19 posts
    Member since:
    Jul 2008

    Posted 08 Jul 2008 Link to this post

    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
  2. Nikolay
    Admin
    Nikolay avatar
    1805 posts

    Posted 09 Jul 2008 Link to this post

    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
  3. Sasmita
    Sasmita avatar
    19 posts
    Member since:
    Jul 2008

    Posted 09 Jul 2008 Link to this post

    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.

  4. Nikolay
    Admin
    Nikolay avatar
    1805 posts

    Posted 11 Jul 2008 Link to this post

    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
  5. Amir
    Amir avatar
    1 posts
    Member since:
    Feb 2017

    Posted 13 Feb 2017 in reply to Nikolay Link to this post

    thank you
Back to Top