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

Fire child insert from parent command item

1 Answer 43 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dustin Dodson
Top achievements
Rank 1
Dustin Dodson asked on 17 May 2010, 02:59 PM
I am trying to fire a nested child insert command from a command item on the parent grid.
I have a GridButtonColumn that I am setting the CommandName to "InsertNest" in the code I can get a hold of the child item, but can not get it to fire the "InitInsert" command.

here is my code behind.

protected void rgvHealthInspList_ItemCommand(object sender, GridCommandEventArgs e) 
        { 
            if (e.CommandName == "InsertNest"
            { 
                GridTableView tblView = e.Item.OwnerTableView as GridTableView;                 
                GridItem[] nTablesViews = tblView.GetItems(GridItemType.NestedView); 
                GridNestedViewItem nTableView = nTablesViews[0] as GridNestedViewItem;                 
                GridTableView nTable = nTableView.NestedTableViews[0];                 
 
                //Attempt 1 
                //nTableView.FireCommandEvent("InitInsert", string.Empty); 
 
                //Attempt 2 
                //nTable.IsItemInserted = true; 
                //nTable.Rebind(); 
                 
                //Attempt 3 
                //nTable.InsertItem(); 
                 
                //Attempt a whole bunch of other trys...... :-( 
                //GridEditableItem nItem = nTable.GetInsertItem(); 
                //nItem.FireCommandEvent("InitInsert", nItem.DataItem); 
                 
                //nTableView.FireCommandEvent("InitInsert", nTable); 
                //nTable.FireCommandEvent("InitInsert", nTable);                 
            } 
        } 

So Obviously I have tried a couple of different ways of doing it, none of them seem to work. I have my grid EditMode setup in PopUp mode if that helps.

Any ideas on how to do this would be great!

Thanks,

Dustin

1 Answer, 1 is accepted

Sort by
0
Dustin Dodson
Top achievements
Rank 1
answered on 17 May 2010, 06:06 PM
OK I finally figured out what the issue is.

For some reason you have to have the child table expanded.

Here is the code that finally worked.

protected void rgvHealthInspList_ItemCommand(object sender, GridCommandEventArgs e) 
        { 
            if (e.CommandName == "InsertNest") 
            {                                 
                e.Canceled = true
                ((GridDataItem)e.Item).Expanded = true
                GridNestedViewItem nTableView = ((GridDataItem)e.Item).ChildItem; 
                GridTableView nTable = nTableView.NestedTableViews[0]; 
                nTable.IsItemInserted = true
                nTable.Rebind(); 
            } 
        } 

Hope this can help someone else if they run into the problem.

Dustin
Tags
Grid
Asked by
Dustin Dodson
Top achievements
Rank 1
Answers by
Dustin Dodson
Top achievements
Rank 1
Share this question
or