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

Extending the RadGridView

3 Answers 102 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.
Andy
Top achievements
Rank 1
Andy asked on 12 Jan 2012, 03:48 PM
Hi,

In my application I have page where I have extended the RadGridView. On the actual grid I have extended the default behaviour in the code behind with things like implmenting a filter by clicking any value. In addtion to this I used a RadToolBar to create a toolbar with common functionality such as print, output to XL, remove all filters and the ability to run some predefined complex filters. For example press button A and get all rows in the UK with outstanding costs > £1000. This is working very well. 

What I would like to do is now package this up so I can reuse the common functionality on other pages. To do this I have created a user control. The basic composition of the user control is like this (obviously there is a lot more XAML!)

 

 

 

 

<UserControl x:Name="MyUserControl">

 

 

 

 

 

 

 

 

    <Grid x:Name="grid">

 

 

 

 

 

 

 

 

        <telerik:RadToolBar x:Name="toolbar"></telerik:RadToolBar>

 

 

 

 

 

 

 

 

        <telerik:RadGridView x:Name="gridView"></telerik:RadGridView>

 

 

 

 

 

 

 

 

    </Grid>

 

 

 

 

 

 

 

 

</UserControl>

 

 

 

 

It would appear from the examples that I have seen so far that in order to expose the properties / objects of the toolbar and the gridview I have to create a DP and set the value in code. This is going to be a lot of work as the hosting page will be defining the gridview columns and the filters to set.

Is it possible for the page on which the user control is placed (host page) to get access to the toolbar and gridview object in XAML? I have created a public variable in the user control that reprsents the grid view but the hosting page does not allow me to reference any of the properties. I am sure I am missign something basic!

As an example how can the host page of the user control above access the RadGridView column collection? Another way to ask the same question is can I make a reference to the RadGridView in the code behind of theuser control that can be seen by the hosting page and recognised as a grid view?

Regards,

Andy Newland




3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 12 Jan 2012, 04:34 PM
Hello Andy ,

What do you mean by "I have created a public variable " . Is that a field , a property or a Dependency property .
What is the type of the property?

What do you mean by "hosting page does not allow me to reference any of the properties"

Does it give compilation errors, or runtime exception , or  the 'variable" is empty ?


Kind regards,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Andy
Top achievements
Rank 1
answered on 12 Jan 2012, 04:56 PM
Thank you for such a promt reply. Maybe it would be easier if make the example simpler.

1. I create a simple user control thus

<UserControl x:Class="MEGrid.MEGrid"
    mc:Ignorable="d"
    d:DesignHeight="800" d:DesignWidth="800">
  
    <Grid Loaded="MEGrid_Loaded" x:Name="APNGrid">
        <TextBox x:Name="APNTextBox" Text="hello" />
    </Grid>
</UserControl>

2. In order to access the proprties of the textbox it appears that I have to create dependency properties for each of the properties I would like to access. Nice and easy:

public static DependencyProperty textBoxTextProp = DependencyProperty.Register("textBoxText", typeof(string), typeof(MEGrid), null);
public string textBoxText
{
    get
    {
        return (string)GetValue(textBoxTextProp);
    }
    set
    {
        SetValue(textBoxTextProp, value);
        this.APNTextBox.Text = value;
    }
}

The markup then becomes

<meControls:MEGrid VerticalAlignment="Top" HorizontalAlignment="Left" Height="300" Width="300" textBoxText="MyText" />

and everything works fine.

My question is that a simple DP like this is not suffcient for a client of the user control to set complex proprties / objects. In my case I need the client to have access to the telerik:RadGridView.Columns collection of the GridView in the user control. I want the user to be able to do something like 

<meControls:MEGrid VerticalAlignment="Top" HorizontalAlignment="Left" Height="300" Width="300" textBoxText="MyText">
    <meControls:MEGrid.TheGrid> <!-- I want a refernce to the actual grid view from the client -->
            <telerik:RadGridView.Columns> <!-- Now I want accesss to all of the properties of the data grid so the user can set the columns -->
            <telerik:GridViewDataColumn Width="1" Header="ID" DataMemberBinding="{Binding CaseID}" IsVisible="False" />
            <telerik:GridViewDataColumn Width="110" Header="Doc ID" DataMemberBinding="{Binding DocID}" IsFilterable="True"  IsGroupable="True" IsReorderable="true" IsResizable="True" IsSortable="True"/>
            <telerik:GridViewDataColumn Width="110" Header="Type" DataMemberBinding="{Binding Type}" IsFilterable="True"  IsGroupable="True" IsReorderable="true" IsResizable="True" IsSortable="True"/>
            <telerik:GridViewDataColumn Width="316" Header="Name" DataMemberBinding="{Binding Name}" IsFilterable="True"  IsGroupable="True" IsReorderable="true" IsResizable="True" IsSortable="True"/>
            <telerik:GridViewDataColumn Width="110" Header="Status" DataMemberBinding="{Binding Status}" IsFilterable="True"  IsGroupable="True" IsReorderable="true" IsResizable="True" IsSortable="True"/>
            <telerik:GridViewDataColumn Width="110" Header="Edit Date" DataMemberBinding="{Binding EditDate}" DataFormatString="dd/MM/yyyy" IsFilterable="True"  IsGroupable="True" IsReorderable="true" IsResizable="True" IsSortable="True"/>
            <telerik:GridViewDataColumn Width="110" Header="Next Action" DataMemberBinding="{Binding NextAction}" IsFilterable="True"  IsGroupable="True" IsReorderable="true" IsResizable="True" IsSortable="True"/>
            <telerik:GridViewDataColumn Width="110" Header="Action FE" DataMemberBinding="{Binding NextActionFE}" IsFilterable="True"  IsGroupable="True" IsReorderable="true" IsResizable="True" IsSortable="True"/>
            <telerik:GridViewImageColumn  DataMemberBinding="{Binding PathToImage}" ImageStretch="None" Width="50" Header="Open" IsFilterable="False"  IsGroupable="False" IsReorderable="False" IsResizable="True" IsSortable="False"  />
        </telerik:RadGridView.Columns>
    </meControls:MEGrid.TheGrid>
</meControls:MEGrid>

How can I reference my UserControl.RadGridView as an object in the client XAML?

Andy 

 

 

 

 

 









0
Pavel Pavlov
Telerik team
answered on 17 Jan 2012, 01:48 PM
Hi,
I am afraid the XAML parser will not support such syntax . Yes you can expose the inner instance of RadGridView, but it can not be initialized in XAML this way. The alternative would be to use code behind .

Regards,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Andy
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Andy
Top achievements
Rank 1
Share this question
or