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

Child GridView BeginEdit or set current cell

4 Answers 323 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Siu Fung
Top achievements
Rank 1
Siu Fung asked on 10 Aug 2009, 09:36 AM
Hi,

I am trying to start edit mode in a cell in child gridview. Since GridView.BeginEdit() can only start edit mode in current cell, I need to set the current cell to be a cell in child gridview, using a similar approach mentioned in the radcontrol reference manual 
ms-help://telerik.winforms.2009.2/telerik.winforms.radgrid/Iterate_the_child_rows_collection_of_a_chosen_parent_row_in_hierarchy_RadGridView.html
i have tried this but it does not work
this.gridview.MasterGridViewTemplate.ChildGridViewTemplates[0].GetChildRows(gridview.Rows[i])[0].IsCurrent = true;  
//or 
this.dgPolicyComment.CurrentRow = this.gridview.MasterGridViewTemplate.ChildGridViewTemplates[0].GetChildRows(gridview.Rows[i])[0]; 
//for some i 
 
//then run this at the end 
this.gridview.GridElement.Update(GridUINotifyAction.Reset); 
for the code above I am trying to set the first row of a child gridview (of i th row of the master gridview) to be current cell

i have also found this post, 
and it seems the author cannot get it working either.
Thanks

Regards,

Derek

4 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 10 Aug 2009, 12:31 PM
Hi Siu Fung,

Currently there is no API that makes a child view current. We will add such API in one of our upcoming releases. This help article shows how to iterate over child views but not how to change the focus. However, you can use the following method as a work around:

public void SetView(RadGridView grid, GridViewInfo viewInfo) 
    if (viewInfo.Rows.Length > 0 && viewInfo.GridViewElement != null
    { 
        GridDataRowElement dataRow; 
        foreach (GridRowElement row in viewInfo.GridViewElement.VisualRows) 
        { 
            dataRow = row as GridDataRowElement; 
            if (dataRow != null
            { 
                grid.GridBehavior.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 
                    dataRow.ControlBoundingRectangle.X + 2, 
                    dataRow.ControlBoundingRectangle.Y + 2, 0)); 
                break
            } 
        } 
    } 

The child view should be expanded first. Here is a sample:

this.radGridView1.Rows[4].IsExpanded = true
SetView( 
    this.radGridView1,  
    this.radGridView1.Rows[4].ChildRow.ChildViewInfo                 
    ); 
this.radGridView1.CurrentView.GridViewInfo.Rows[2].IsCurrent = true
this.radGridView1.CurrentView.GridViewInfo.ViewTemplate.Columns[1].IsCurrent = true
this.radGridView1.BeginEdit(); 

I hope this helps. Should you have any questions, don't hesitate to ask.

All the best,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Siu Fung
Top achievements
Rank 1
answered on 10 Aug 2009, 02:50 PM
Hi Jack,

Thank you for your reply.
I have just tried the code, I can see that the cursor has been moved a child cell, but BeginEdit() is not working.
In the source code of RadGridView, i found that the BeginEdit() method will start edit mode of "CurrentCell", however, the value of the  readonly CurrentCell is null. Also, the BeginEdit() method return false which indicates the process is not successful.
Is there any way I can assign the current cell?
Thanks

Regards,

Derek
0
Jack
Telerik team
answered on 11 Aug 2009, 12:53 PM
Hi Siu Fung,

Interesting, this worked in my test project. You can set the current cell by setting the CurrentColumn and CurrentRow properties. For example:

this.radGridView1.CurrentView.GridViewInfo.Rows[2].IsCurrent = true;  
this.radGridView1.CurrentView.GridViewInfo.ViewTemplate.Columns[1].IsCurrent = true;  

Please send me your application and I will try to find a proper solution. I am looking forward to your reply.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Siu Fung
Top achievements
Rank 1
answered on 11 Aug 2009, 02:44 PM
I found that if an invisible current column is set to "current", the CurrentCell property will be set to null (maybe an exception should be thrown?), and it causes value inconsistency between CurrentRow/CurrentColumn and CurrentCell. And therefore BeginEdit() could not find the "CurrentCell" to start edit mode.
So I have fixed my problem now.
Thanks
Tags
GridView
Asked by
Siu Fung
Top achievements
Rank 1
Answers by
Jack
Telerik team
Siu Fung
Top achievements
Rank 1
Share this question
or