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

Create usercontrol with Gridview

8 Answers 361 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vaithi
Top achievements
Rank 1
Vaithi asked on 22 Jan 2009, 07:52 AM
Hi,

I wanted to create a usercontrol in WPF using a gridview and two buttons and wanted to use this usercontrol in another win form.

I have tried many ways to bind the usercontrol with some data. I am not able to achieve the same.

Please help me with some sample project will be highly appreciated.

Thanks!

Vaithi.

8 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 22 Jan 2009, 12:06 PM
Hi Vaithi,

You can find small demo application attached.

All the best,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Khwaja
Top achievements
Rank 1
answered on 06 Oct 2009, 02:41 PM
how can i use user control within GridView ? i have created User Control and i want to add this user control within GridView may be as a column. i am using WinForms GridView control. can you please guide me how to use it.
0
Vlad
Telerik team
answered on 06 Oct 2009, 02:43 PM
Hi Khwaja,

This forum is for our WPF grid.

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Diego
Top achievements
Rank 1
answered on 09 Sep 2010, 08:54 PM
And If I want to define the columns (AutoGenerateColumns="False") ?? How do I do? It's possible?

Diego Ferreira
0
Vlad
Telerik team
answered on 10 Sep 2010, 07:21 AM
Hello,

You can check our demos for more info.

All the best,
Vlad
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
Diego
Top achievements
Rank 1
answered on 10 Sep 2010, 12:33 PM
You don't understanding! :)

I'm developing an user control. It is composed RadGridView and RadDataPager. In code behind, I create a property called 'Columns' of type GridViewColumnsCollection, for I set the columns in the window.

In the Window, I'm put my user control and works. But, If the window has 2 or more UserControl's, all the columns stays in the first User control, and the anothers grid's has no columns.

Code of the first user control in window:

<userControls:DataGridNotas x:Name="dtgOne" Height="120" Width="775"
SelectedItem="{Binding Path=MySelectedObject, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
ListaBinding="{Binding Path=MySource, UpdateSourceTrigger=PropertyChanged}">
    <userControls:DataGridNotas.Columns>
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Column1}" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Column2}" />
        </userControls:DataGridNotas.Columns>
</userControls:DataGridNotas>

This code is second user control in the Window

<userControls:DataGridNotas x:Name="dtgTwo" SelectedItem="{Binding Path=MySelectedObject2, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
 ListaBinding="{Binding Path=MySource2, UpdateSourceTrigger=PropertyChanged}">
    <userControls:DataGridNotas.Colunas>
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Column3}" Width="220" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Column4}" Width="220" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Column5}" Width="170" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Column6}" Width="200" />
         </userControls:DataGridNotas.Colunas>
</userControls:DataGridNotas>

  • So, the columns stays only in dtgOne and the dtgTwo has no column.


  • the Dependency Property in User control:


public static readonly DependencyProperty ColumnsProperty =
       DependencyProperty.Register("Columns", typeof(GridViewColumnCollection), typeof(DataGridNotas),
       new UIPropertyMetadata(new GridViewColumnCollection()));
[Bindable(true, BindingDirection.TwoWay)]
public GridViewColumnCollection Columns
{
    get { return (GridViewColumnCollection)GetValue(ColumnsProperty); }
        set { SetValue(ColumnsProperty, value); }
}
Sorry the bad english =/

Diego Ferreira.
0
Stefan Dobrev
Telerik team
answered on 16 Sep 2010, 08:27 AM
Hello Diego,

You will have to initialize your columns collection in the constructor of your UserControl. Having its default value to a new GridViewColumnCollection in the dependency property metadata will make this collection shared between all the instances of your control. So you should make the default value null in the metadata and initialize it in the constructor to a new instance of GridViewColumnCollection.

You can also check this blog post which explains the problem you are facing.

Sincerely yours,
Stefan Dobrev
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
Diego
Top achievements
Rank 1
answered on 16 Sep 2010, 12:33 PM
Thank you very much!!!!

=]

Work fine!

Thanks a lot!
Tags
GridView
Asked by
Vaithi
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Khwaja
Top achievements
Rank 1
Diego
Top achievements
Rank 1
Stefan Dobrev
Telerik team
Share this question
or