How to make the focus remain on the same treeList node?

442 Views Asked by At

Document structure
Form_1:
- Panel1: - gridView;
- Panel2: - treeList;
- Panel3: - UserControl (depending on the selected tree node);

Scenario_1:
  - User. selects a row in the grid.
  - Code. Sends to the variable the "ID" value of the row that the focus is on in the gridView. (handled by the gridView event).
  - Code. By default, focus is placed on the node "Node_1" treeList (handled by the gridView event).

  - User. selects a node in treeList.
  - in Panel3, a UserControl is displayed, which corresponds to the "ID" row from the gridView and the "ID" of the node from treeList (processed by the treeList event);

Scenario_2:
User. Moves focus only across the rows in the gridView,
and in treeList, the focus is always on the same node.
Problem: Panel3 displays user control "UserControl_1", which matches only for grid_1 "row_1".
How to make it happen:
- Panel1 --- Panel2 ----- Panel3
- "lines_1" - "Node_1" - "UserControl_1";
- "lines_2" - "Node_1" - "UserControl_2";
- "lines_3" - "Node_1" - "UserControl_3";

Question.
How to fix the problem "Scenario_2"?

 private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
    try
    {                
        idParser = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID"));                

        TreeListNode nodeFocus = treeList2.FindNodeByKeyID(20);
        treeList2.SetFocusedNode(nodeFocus);
    }
    catch (Exception)
    {
        return;        
    }
}


        private void treeList2_AfterFocusNode(object sender, NodeEventArgs e)
        {
            int idNode = Convert.ToInt32(e.Node.GetValue("ID")); // "ID" вбыранного узла

            switch (idNode)
            {
                case 20: 

                    pathToSettingsMain = maskPath + idParser.ToString() + ".xml";                                                                                               

                    f01startURLs = new F01StartURLs(pathToSettingsMain);
                    splitContainer2.Panel2.Controls.Clear();
                    splitContainer2.Panel2.Controls.Add(f01startURLs);

                    userControlCurent = f01startURLs;

                    break;

            }
1

There are 1 best solutions below

3
On

You need to configure your current UserControl in the gridView1_FocusedRowChanged event handler as well. If an end-user select a node in TreeList, the treeList2_AfterFocusNode event will be also raised and the current UserControl will be changed correspondingly.