I have check box to enable/ disable controls. it is outside the gridview. I want to make gridview disable when unchek checkbox , but data should be scrolled (scroll should not get disabled) so how can I achieve that.
In gridview there is DataTemplate and in that there is Button control.. If i can find button i can make it enable / disable. that is one option.But how can i find button control on check box click,
Please give any solution.
Thanks,
Mahendra
6 Answers, 1 is accepted
You may try to set the IsReadOnly property of the grid - thus you will be able to scroll it without editing it.
As for finding an element inside RadGridView, you may use the ChildrenOfType<T> extension method. For example:
RadButton button = this.clubsGrid.ChildrenOfType<
RadButton
>().FirstOrDefault();
Maya
the Telerik team

I tried with Readonly but not working. Can you give complete code how to find button in gridview. my xaml code is as below
<telerikGrid:GridViewDataColumn Header="ADD TO CONTACTS" HeaderTextAlignment="Center" IsResizable="False">
<telerikGrid:GridViewDataColumn.CellTemplate>
<DataTemplate>
<StackPanel x:Name="stpAction" Orientation="Horizontal" HorizontalAlignment="Left">
<Button x:Name="btnAdd">
</Button>
</StackPanel>
</DataTemplate>
</telerikGrid:GridViewDataColumn.CellTemplate>
</telerikGrid:GridViewDataColumn>
I have tested the case when setting IsReadOnly property of the grid, but still I was able to scroll it without any problems. I am sending you the sample I used so that you may verify whether there are any misunderstandings on your requirements. The project illustrates also how you may find a particular button defined in a CellTemplate for a column.
Maya
the Telerik team

by setting IsreadOnly gridview becomes disable, but i want to disable Button inside DataTemplate, so that click event should not get fired. So how can i do that?
Thanks,
Mahendra
You may set the IsEnabled property of the button to "False".
Maya
the Telerik team

It would be nice if you give sample with Findcontrol (Give updated sample that you given in previous reply)
I tried with following code
Button ControlToSearch = FindControl<Button>(MyDataGrid, typeof(Button), "btnAdd");
public T FindControl<T>(UIElement parent, Type targetType, string ControlName) where T : FrameworkElement
{
if (parent == null) return null;
if (parent.GetType() == targetType && ((T)parent).Name == ControlName)
{
return (T)parent;
}
T result = null;
int count = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < count; i++)
{
UIElement child = (UIElement)VisualTreeHelper.GetChild(parent, i);
if (FindControl<T>(child, targetType, ControlName) != null)
{
result = FindControl<T>(child, targetType, ControlName);
break;
}
}
return result;
}
But not getting button
Thanks,
Mahendra