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

CheckBox column in neste

1 Answer 12 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Prasad
Top achievements
Rank 1
Prasad asked on 11 Jun 2014, 08:03 PM
Hi,

I am using GridView control to display data in a nested grid view format. I am loading data dynamically as shown in 'Load On Demand' sample for GridView control. I need to display the data in nested grid view format and for that I am creating a child template and adding it to 'Templates' collection in RowSourceNeeded event handler. Upt o this point, everything works fine.

The problem I am facing is I need to display a checkbox column only at the leaf level in the nested grid. And the leaf node can appear at different level for each parent node. For e.g. node 1 can have just 1 child which is leaf as well. Node 2 can have 1 child which further has 1 child [grandchild], which is the leaf node.

If I add GridViewCheckBoxColumn into child template, it gets displayed for all the nested grids, which is not required.

Can you please advise me how to display checkbox column only for the leaf nodes in all the nested grids in GridView control.

Thanks.

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 16 Jun 2014, 04:58 PM
Hello Prasad,

Thank you for writing.

Single template can have a particular number of columns and at each point a column from the template can be either visible or not. This means that you can show or hide this column for all the views that you have. And the column will be visible or not for all currently visible templates. And the desired behavior can be achieved if you have only one template of this type opened. For example:
void radGridView1_ChildViewExpanded(object sender, ChildViewExpandedEventArgs e)
{
    Console.WriteLine(e.ParentRow.Cells[0].Value.ToString());
    if (((int)e.ParentRow.Cells[0].Value) % 2 == 0)
    {
        e.ChildViewInfo.ViewTemplate.Columns["CategoryID"].IsVisible = false;
    }
    else
    {
        e.ChildViewInfo.ViewTemplate.Columns["CategoryID"].IsVisible = true;
    }
    radGridView1.BeginUpdate();
    foreach (GridViewRowInfo item in radGridView1.MasterTemplate.Rows)
    {
        if ((int)item.Cells[0].Value != (int)e.ParentRow.Cells[0].Value)//use unique for the row value
        {
            item.IsExpanded = false;
        }
        else
        {
            item.IsExpanded = true;
        }
    }
    radGridView1.EndUpdate();
}

I hope this helps. Should you have any other questions do not hesitate to ask.
 
Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Prasad
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or