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

How to disable Gridview, but scroll should enabled

6 Answers 337 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mahendra
Top achievements
Rank 1
Mahendra asked on 14 Jun 2011, 01:42 PM
Hello,

 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

Sort by
0
Maya
Telerik team
answered on 14 Jun 2011, 03:04 PM
Hi Mahendra,

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();

Regards,
Maya
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
Mahendra
Top achievements
Rank 1
answered on 14 Jun 2011, 03:30 PM
hello,

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>

 

0
Maya
Telerik team
answered on 14 Jun 2011, 03:49 PM
Hello Mahendra,

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.
 

Regards,
Maya
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
Mahendra
Top achievements
Rank 1
answered on 15 Jun 2011, 10:45 AM
Hello,
 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
0
Maya
Telerik team
answered on 15 Jun 2011, 12:14 PM
Hello Mahendra,

You may set the IsEnabled property of the button to "False".
 

Regards,
Maya
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
Mahendra
Top achievements
Rank 1
answered on 15 Jun 2011, 12:23 PM
yes, but for that I want to find button in Datatemplate on checkbox chek event. So please give code to find button control

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 

Tags
GridView
Asked by
Mahendra
Top achievements
Rank 1
Answers by
Maya
Telerik team
Mahendra
Top achievements
Rank 1
Share this question
or