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

Hierarchical Grid

4 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rajiv
Top achievements
Rank 1
Rajiv asked on 25 Nov 2008, 03:30 PM
Hi,
I have a single level hierarchical grid with 3 detail tables. The Master grid is having the paging and sorting enabled. My requirement is when the user adds a new record in the master table, I want that record to be selected and it's node to be opened(expanded). This should work even if the sort is enable for any of the column.

To select and Open the newly entered node, I tried using RadGrid1.SelectedIndexes.Add( j, 0) method in the prerender event of the rad grid control. but it doesn't seem to work.

Please help.

Thanks,
Rajiv

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Nov 2008, 05:20 AM
Hi Rajiv,

Go through the following code library submission which demostrates how to identify and select the last inserted row using its key value. You can use a similar approach to select and expand the newly inserted row.
Select Last Inserted Row

Thanks
Shinu.
0
Rajiv
Top achievements
Rank 1
answered on 26 Nov 2008, 06:56 AM
Thank you for the reply, Shinu.

I have already refered to the sample code below and I am able to select the last inserted row. But my problem is that I am not able to programmatically expand that selected node. I tired using the SelectedIndexes method in the prerender even of the Radgrid but it is not working.

Please help.

Thanks,
Rajiv 
0
Accepted
Princy
Top achievements
Rank 2
answered on 26 Nov 2008, 07:28 AM
Hello  Rajiv,

You can use the same approach to expand the item as well.

CS:
protected void RadGrid1_PreRender(object sender, EventArgs e)   
    {   
       if(!RadGrid1.MasterTableView.IsItemInserted) 
       {  
        // Get the CategoryID of the last inseted record   
        OleDbConnection MyOleDbConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~//App_Data//Nwind.mdb"));   
        dtTable = new DataTable();   
  
        MyOleDbConnection.Open();   
        try   
        {   
            MyOleDbCommand.CommandText = "SELECT MAX(CategoryID) FROM  Categories";   
            MyOleDbCommand.Connection = MyOleDbConnection;   
            intLastCategoryID =Convert.ToInt16(MyOleDbCommand.ExecuteScalar().ToString());   
  
        }   
        finally   
        {   
            MyOleDbConnection.Close();   
        }   
           
        // Compare the CategoryID of the each item with the newly inserted record CategoryID    
        // and select the last inserted row   
        foreach (GridDataItem item in RadGrid1.Items)   
        {   
            int intCategoryID = Convert.ToInt16(item["CategoryID"].Text);   
            //checking the for the newly inserted ID
            if (intCategoryID == intLastCategoryID)   
            {   
                item.Selected = true
  
               //Expand the item 
               item.Expanded = true;  
            }   
        }   
      }  
    }   

Regards
Princy
0
Rajiv
Top achievements
Rank 1
answered on 26 Nov 2008, 07:46 AM
Thank you, it works.

-Rajiv
Tags
Grid
Asked by
Rajiv
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Rajiv
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or