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

Column Selection Color

4 Answers 125 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Scott Michetti
Top achievements
Rank 1
Iron
Scott Michetti asked on 01 Nov 2013, 08:40 PM
Hello, when selecting a cell, the row is highlighted. I would like to have the cells on selection by column, not by row. I'm using dynamic columns, so I'm not sure how to do this. I tried e.Cell.Background = Brushes.Red; at the cell level but the colors didn't change.

Thanks,
Scott

4 Answers, 1 is accepted

Sort by
0
Scott Michetti
Top achievements
Rank 1
Iron
answered on 05 Nov 2013, 04:07 PM
Any thoughts on this one? This is my code when creating a dynamic column. Maybe I need to add a ConditionDataTemplateSelector but I don't know how to do this in code. All the examples of changing background color have fixed GridViewDataColumns, not dynamic.
void grdRows_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
        {
            
            GridViewDataColumn dc2 = e.Column as GridViewDataColumn;
            
            dc2.DataMemberBinding = new Binding(e.Column.Header.ToString());
            FrameworkElementFactory feTb2 = new FrameworkElementFactory(typeof(TextBlock));            
            FrameworkElementFactory feB2 = new FrameworkElementFactory(typeof(Border));
            feB2.SetValue(Border.PaddingProperty, new Thickness(3));
            feB2.SetValue(Border.CornerRadiusProperty, new CornerRadius(3));
            feB2.SetValue(Border.BorderBrushProperty, new SolidColorBrush(Colors.Black));
            feB2.SetValue(Border.BorderThicknessProperty, new Thickness(1));
            feB2.AppendChild(feTb2);
            feTb2.SetBinding(TextBlock.TextProperty, new Binding(e.Column.Header.ToString()));
            DataTemplate dt2 = new DataTemplate();
            dt2.VisualTree = feB2;
            dt2.Seal();            
            
            dc2.CellTemplate = dt2;

           
        }
0
Yoan
Telerik team
answered on 06 Nov 2013, 04:55 PM
Hi Scott,

I am sorry, but I am not sure that I can understand your question. 

Could you clarify what is the exact behavior that you want to achieve ? Do you want to select only a cell not the full row?

Thank you in advance!

Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Scott Michetti
Top achievements
Rank 1
Iron
answered on 13 Nov 2013, 02:50 PM
Thanks Yoan, what I want is when the user selects a single cell, all cells in that column to be highlighted. So if the user selects cell row 3, column 2, all cells in column 2 will be red for instance.

Thanks
0
Yoan
Telerik team
answered on 18 Nov 2013, 02:01 PM
Hello Scott,

I am afraid that GridView does not offer this feature out of the box. However, I can suggest a possible workaround that could be used to achieve the desired functionality. You can use a combination of CellStyleSelectors for the columns, and some kind of flags in your business objects that says whether a column should be highlighted. Note that having a style selector for every column, could result in a possible performance hit.

Let me know if I can assist you further with the issue. 

Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Scott Michetti
Top achievements
Rank 1
Iron
Answers by
Scott Michetti
Top achievements
Rank 1
Iron
Yoan
Telerik team
Share this question
or