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

[Solved] how to expand parent of newly added row

2 Answers 72 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.
Carl
Top achievements
Rank 1
Carl asked on 28 Jun 2011, 07:33 PM
Hi,

I am adding a row to a hierarchical gridview programatically.  The row is in the child gridview of the selected row.  I am able to add the row using the underlying data, but if the parent row is not expanded, one cannot immediately see the new row, so I want to automatically expand the parent row when the new row is added.  All of the events that I have been able to trap do not seem to have access to the RadRowItem so I can expand the parent row.  They all seem to have access to the underlying data but not the ui element.  Also, since I am using the Click event to add the row instead of the ICommand beginInsertRow, the AddingRow event does not seem to fire.  Please let me know how I can achieve the result that I need.  Thanks,

Carl

snippet that adds the row:

private

 

 

void insertOption_Click(object sender, RoutedEventArgs e)

 

{

 

 

var expandCommand = RadGridViewCommands.ExpandHierarchyItem as RoutedUICommand;

 

 

 

if (selectedItem == null)

 

{

 

 

return;

 

}

 

 

if (selectedItem.GetType() == typeof(RadGridView))

 

{

 

 

var rgv = (RadGridView)selectedItem;

 

 

 

if (rgv != null)

 

{

 

 

Object o = rgv.SelectedItem;

 

 

 

if (o != null)

 

{

 

 

// check if optionssheet style,option,bom, or component

 

 

 

if (o.GetType() == typeof(OptionsSheet))

 

{

addStyle(o);

}

 

 

else if (o.GetType() == typeof(RadControlsSilverlightApp5.com.tradestonesoftware.optionssheet.model.Style))

 

{

addOption(o);

}

 

 

else if (o.GetType() == typeof(Option))

 

{

addBom(o);

}

 

 

else if (o.GetType() == typeof(Bom))

 

{

addComponent(o);

}

}

}

}

}

 

 

private void addBom(object o)

 

{

 

 

Option option = (Option) o;

 

option.boms.Add(

 

new Bom());

 

}

 

 

private void addOption(object o)

 

{

    RadControlsSilverlightApp5.com.tradestonesoftware.optionssheet.model.

 

Style style=(RadControlsSilverlightApp5.com.tradestonesoftware.optionssheet.model.Style)o;

 

    style.options.Add(

 

new Option());

 

}

 

 

private void addStyle(object o)

 

{

 

 

    OptionsSheet sheet = (OptionsSheet)o;

 

    sheet.styles.Add(

 

new RadControlsSilverlightApp5.com.tradestonesoftware.optionssheet.model.Style());

 

}


2 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 29 Jun 2011, 10:01 AM
Hi Carl,

You may do the following:

var selectedClub = this.clubsGrid.SelectedItem as Club;
                if (selectedClub != null)
                {
                    selectedClub.Players.Add(new Player() { Name = "New Player" });
                }
 
                var selectedRow = this.clubsGrid.ItemContainerGenerator.ContainerFromItem(this.clubsGrid.SelectedItem) as GridViewRow;
                if ((selectedRow).HasHierarchy)
                {
                    selectedRow.IsExpanded = true;
                }

I am sending you a sample project illustrating the suggested approach.

  Kind regards,
Maya
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
Carl
Top achievements
Rank 1
answered on 29 Jun 2011, 02:06 PM
Thanks for the help.  That is exactly what I was looking for.

Carl
Tags
GridView
Asked by
Carl
Top achievements
Rank 1
Answers by
Maya
Telerik team
Carl
Top achievements
Rank 1
Share this question
or