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

[Solved] CellStyle and HeaderCellStyle Questions

3 Answers 232 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
ChiFai.Chan
Top achievements
Rank 1
ChiFai.Chan asked on 17 Feb 2010, 12:57 AM
Hi,

I have a question on getting the default cell and header cell styles for the Telerik gridview. For other styles (i.e: RowStyle), I can do a right-click on the grid in Blend, , then edit "RowStyle", and the default style would be created in xaml.

However, I do not see that option for cell and header cell styles. Can you please show me how to obtain the default styles for those?

Another question I have is how to apply these styles to columns. I have gone through several posts, and the common suggestion is to do it from code behind. However, if I have my styles in a resource dictionary file, I cannot retrieve those styles from my code behind. Could you please provide a suggestion on this?

Thank you very much
Ernest

3 Answers, 1 is accepted

Sort by
0
Kalin Milanov
Telerik team
answered on 17 Feb 2010, 09:42 AM
Hello ChiFai.Chan,

CellStyle and HeaderCellStyle are properties of the grid's column and as the columns are logical elements you cannot get them from RadGridView control directly. What you can do is draw a GridViewHeaderCell and / or GridViewHeaderCell on Blend's design surface and edit its style. Once done editing delete the cells but keep the styles.

There are two options to apply those styles. One is to define the columns of the grid in XAML and use the CellStyle and HeaderCellStyle properties to set the styles. If you are auto generating the columns then you will need to do it in code. Below is a snippet of what the code should look like:
public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();          
            this.gridView.DataLoaded += new System.EventHandler<System.EventArgs>(gridView_DataLoaded);
        }
        private void gridView_DataLoaded(object sender, System.EventArgs e)
        {
            foreach (var col in this.gridView.Columns)
            {
                col.CellStyle = (Style)this.Resources["MyCellStyle"];
                col.HeaderCellStyle = (Style)this.Resources["MyHeaderCellStyle"];
            }
        }
    }

Let me know how this goes.

Greetings,
Kalin Milanov
the Telerik team


Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
ChiFai.Chan
Top achievements
Rank 1
answered on 17 Feb 2010, 06:34 PM
Thanks for the reply. Final question, I tried to set the CelllStyle and HeaderCellStyle on a column in Blend through xaml. However, whenever I do so, Blend would crash. Have you experienced or heard of similar experience?

Thanks,
Ernest
0
Kalin Milanov
Telerik team
answered on 18 Feb 2010, 12:30 PM
Hi ChiFai.Chan,

Yes. It is something we are working on resolving as well. I understand it is very annoying to switch between Blend and another editor just for that small piece of XAML for which I would like to offer my most sincere apologies.

Sincerely yours,
Kalin Milanov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
ChiFai.Chan
Top achievements
Rank 1
Answers by
Kalin Milanov
Telerik team
ChiFai.Chan
Top achievements
Rank 1
Share this question
or