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

[Solved] Self-Referencing Hierarchy Duplicated Rows

3 Answers 165 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.
Joseph
Top achievements
Rank 1
Joseph asked on 07 Jul 2011, 02:13 PM
Hi guys,

I followed the Self-Referencing Hierarchy example in the demos section to create a GridView with nested childs rows.

My DataModel contains of course an ID and ParentID plus other attributes.

Let's say we have  3 rows as follow :

ID = 1, ParentID = 0
ID = 2, ParentID = 0
ID = 3, ParentID = 2

As we can see, the third row is child of the second row.

Now when I bind the grid to this list of data, I get 3 visible rows and the second row contains the third row when u collpase it. I don't know why the GridView show the third row seeing that it is the child if the second Row.

Any idea ?

3 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 08 Jul 2011, 07:22 AM
Hello Joseph,

This is by design but you can easily hide such rows from appearing on the root level by creating a filter descriptor which would only allow rows with ParentID equal to 0.

Hope this helps.

Greetings,
Milan
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Joseph
Top achievements
Rank 1
answered on 08 Jul 2011, 08:31 AM
Thanks for the heads up.

I used this code :

<controls:RadGridView.FilterDescriptors>
                           <data:FilterDescriptor Member="ParentID" Operator="IsEqualTo" Value="0"/>
                           
                            
                       </controls:RadGridView.FilterDescriptors>

I have one more issue.

I want to create dynamically a custom column in the child Grid. This column will contain some buttons. And I want to assign them some handlers like Click and load.

How can I achieve these 2 issues ?

I create the columns at code behind inside the DataLoading event handler of the GridView as follow :

private void RadGridView1_DataLoading(object sender, GridViewDataLoadingEventArgs e)
       {
           GridViewDataControl dataControl = (GridViewDataControl)sender;
            
           if (dataControl.ParentRow != null)
           {
               
               dataControl.ShowGroupPanel = false;
               dataControl.AutoGenerateColumns = false;
               dataControl.CanUserFreezeColumns = false;
               dataControl.IsReadOnly = true;
               dataControl.ChildTableDefinitions.Clear();
 
               GridViewDataColumn column = new GridViewDataColumn();
               column.DataMemberBinding = new System.Windows.Data.Binding("ProjectName");
               dataControl.Columns.Add(column);
 
               column = new GridViewDataColumn();
               column.DataMemberBinding = new System.Windows.Data.Binding("FileName");
               dataControl.Columns.Add(column);
 
               column = new GridViewDataColumn();
               column.DataMemberBinding = new System.Windows.Data.Binding("PONumber");
               dataControl.Columns.Add(column);
 
               column = new GridViewDataColumn();
               column.DataMemberBinding = new System.Windows.Data.Binding("TargetLanguage");
               dataControl.Columns.Add(column);
 
 
 
 
            
           }
       }
0
Milan
Telerik team
answered on 14 Jul 2011, 08:48 AM
Hi Joseph,

What you can do in this situation is define a custom cell template template for your button column:

<Window.Resources>
    <my:MyViewModel x:Key="MyViewModel"/>
    <DataTemplate x:Key="columnTemplate">
        <Button Content="MyButton"/>
    </DataTemplate>
</Window.Resources>

Then in RadGridView1_DataLoading create the button column and apply its CellTemplate:

GridViewDataColumn column = new GridViewDataColumn();
                column.CellTemplate = this.Resources["columnTemplate"] as DataTemplate;
                dataControl.Columns.Add(column);

Finally you should subscribe for Button's Click event:

public MainWindow()
{
    InitializeComponent();
  
    this.playersGrid.DataLoading += new EventHandler<GridViewDataLoadingEventArgs>(playersGrid_DataLoading);
    this.AddHandler(Button.ClickEvent, new RoutedEventHandler(OnButtonClick));
}
  
private void OnButtonClick(object sender, RoutedEventArgs e)
{
  
}

Hope this helps.


Kind regards,
Milan
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
GridView
Asked by
Joseph
Top achievements
Rank 1
Answers by
Milan
Telerik team
Joseph
Top achievements
Rank 1
Share this question
or