Focus Navigation between two grids

1 Answer 124 Views
GridView
Bidder
Top achievements
Rank 1
Bidder asked on 20 Nov 2021, 02:18 PM

Hi.

I have two gridviews in a form: Master and Detail. I am trying to set the focus on Detail Grid when the Master grid UserAddedRow Event occurs. I tried with Telerik grids, but, it doesn't work. The focus always stays in the Master grid.

In other question, you answer me with the below code sample, but, this sample shows the Detail grid inside the Master grid. My customer wants to do what I am showing in the PNG attachment, in order to make the fingering fast.

The sample in PNG was developed in native VS DataGridView.

Thanks

Code sample:

  DataTable masterTable = new DataTable();
        DataTable childTable = new DataTable();

        public RadForm1()
        {
            InitializeComponent();

            masterTable.Columns.Add("Id", typeof(int));
            masterTable.Columns.Add("Name", typeof(string));
            for (int i = 0; i < 3; i++)
            {
                masterTable.Rows.Add(i, "Row" + i);
            }
            childTable.Columns.Add("Id", typeof(int));
            childTable.Columns.Add("ParentId", typeof(int));
            childTable.Columns.Add("Title", typeof(string));
            childTable.Columns.Add("Date", typeof(DateTime));
            Random rand = new Random();
            for (int i = 0; i < 20; i++)
            {
                childTable.Rows.Add(i, rand.Next(0, 3), "Child" + i, DateTime.Now.AddDays(i));
            }

            radGridView1.DataSource = masterTable;
            radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

            GridViewTemplate template = new GridViewTemplate();
            template.DataSource = childTable;
            template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            radGridView1.MasterTemplate.Templates.Add(template);

            GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate);
            relation.ChildTemplate = template;
            relation.RelationName = "MasterChild";
            relation.ParentColumnNames.Add("Id");
            relation.ChildColumnNames.Add("ParentId");
            radGridView1.Relations.Add(relation);

            this.radGridView1.UserAddedRow+=radGridView1_UserAddedRow; 
        } 

        private void radGridView1_UserAddedRow(object sender, GridViewRowEventArgs e)
        {
            e.Row.IsExpanded = true;
            this.radGridView1.CurrentRow = ((GridViewHierarchyRowInfo)e.Row).Views[0].TableAddNewRow;
            this.radGridView1.CurrentColumn = this.radGridView1.MasterTemplate.Templates[0].Columns[0];
            this.radGridView1.BeginEdit(); 
        }

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Nov 2021, 11:42 AM
Hello,  

If you need to have two separate grids for the master and child records, I would recommend you to have a look at the following KB article which is quite useful on this topic:
https://docs.telerik.com/devtools/winforms/knowledge-base/master-detail-in-two-grids 

The following code snippet demonstrates how to focus the second grid and activate the editor for it once the user added a new row in the first grid.
        private void RadGridView1_UserAddedRow(object sender, GridViewRowEventArgs e)
        {
            this.ActiveControl = this.radGridView2;
            this.radGridView2.CurrentRow = this.radGridView2.MasterView.TableAddNewRow;
            this.radGridView2.BeginEdit();
        }

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
GridView
Asked by
Bidder
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or