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

Exposing Columns from inside a UserControl

1 Answer 230 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mary
Top achievements
Rank 1
Mary asked on 22 Aug 2020, 03:14 PM

Hi,

We have a series of views consisting of a search box, search options and then a results RadGridView. Since the functionality & bindings is the same on each, we have a UserControl that holds the search box & search options functionality. The only difference between each view is the Columns in RadGridView, so we are trying to put the RadGridView inside the UserControl and allow the columns to be specified by the implementing view.

Do you know how we could achieve this?

Roughly what we're trying to do:

 <UserControl x:Class="UserControls.BaseSearch" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
    Height="Auto"  Width="Auto"> 
<Grid> 
<telerik:RadGridView Margin="0" Name="radGridView1" ItemsSource="{Binding SearchResults}" /> 
</Grid> 
</UserControl> 

<UserControl x:Class="Views.CustomerSearch" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
    xmlns:userControls="http://schemas.telerik.com/2008/xaml/presentation" 

    Height="Auto"  Width="Auto"> 
    <Grid> 
<userControls:BaseSearch>
<telerik:RadGridView.Columns>

<telerik:GridViewDataColumn Header="Reference"
Name="Reference"
DataMemberBinding="{Binding Reference}" Width="100">
</telerik:GridViewDataColumn>

<telerik:GridViewDataColumn Header="Description"
DataMemberBinding="{Binding Description}"
Width="200" />

<telerik:GridViewDataColumn Header="Start Date"
DataMemberBinding="{Binding StartDate, StringFormat=d}"
ShowDistinctFilters="False"
Width="130" />

</telerik:RadGridView.Columns>
</userControls:BaseSearch>
    </Grid> 
</UserControl> 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 26 Aug 2020, 09:53 AM

Hello Stewart,

Thank you for the shared code snippet. 

Can you check out the following SDK example: BindingColumnsFromViewModel? It demonstrates how you can create columns inside a viewmodel and transfer them to the RadGridView, however you can adapt this approach to creating the Columns inside the UserControl. 

I hope you find this helpful.

Regards,
Vladimir Stoyanov
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

Tags
GridView
Asked by
Mary
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Share this question
or