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

[Solved] How to get handle to CellTemplate control to manipuate

1 Answer 91 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.
Grr
Top achievements
Rank 1
Grr asked on 07 Dec 2010, 07:37 PM
I am trying to put color picker in a dropdownbutton. I want once the user selects the color the dropdown should close.

My column defination
 <telerik:GridViewDataColumn Header="Color"
                    x:Name="Color"
                    DataMemberBinding="{Binding Path=ColorBrush, Mode=TwoWay}"
                    Width="40"
                    UniqueName="Color">
       <telerik:GridViewDataColumn.CellTemplate>
           <DataTemplate>
               <telerik:RadDropDownButton Background="{Binding Path=ColorBrush, Mode=TwoWay}" 
Name
="ColorDropDown1"
                     Width="20" Height="15" DropDownWidth="187" CornerRadius="3" 
                     DropDownIndicatorVisibility="Collapsed" >
                                <telerik:RadDropDownButton.DropDownContent>
                                    <telerik:RadColorSelector 
                                        SelectedColor="{Binding Path=ColorBrush, Mode=TwoWay}" 
                                        SelectedColorChanged="RadColorPicker_SelectedColorChanged"/>
                                </telerik:RadDropDownButton.DropDownContent>
               </telerik:RadDropDownButton>
            </DataTemplate>
         </telerik:GridViewDataColumn.CellTemplate>

in code I am trying to get to the control by

private void RadColorPicker_SelectedColorChanged(object sender, EventArgs e)
        {
            (mRadGridView.SelectedItem as ChannelProperty).ColorBrush = new SolidColorBrush((sender as RadColorSelector).SelectedColor);
            RadDropDownButton button = FindVisualChildByName<RadDropDownButton>(this"ColorDropDown1");
            button.IsOpen = false;
        }

        private static T FindVisualChildByName<T>(DependencyObject parent, string name) where T : DependencyObject
        {
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
            {
                var child = VisualTreeHelper.GetChild(parent, i);
                string controlName = child.GetValue(Control.NameProperty) as string;
                if (controlName == name)
                {
                    return child as T;
                }
                else
                {
                    T result = FindVisualChildByName<T>(child, name);
                    if (result != null)
                        return result;
                }
            }
            return null;
        }
It only works for first row but not for all. Any help?

1 Answer, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 08 Dec 2010, 11:23 AM
Hi Giri,


I would suggest you to create your own custom editor with RadGridView as it is shown in this online documentation article.


All the best,
Vanya Pavlova
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
GridView
Asked by
Grr
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Share this question
or