Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have an invoice form with a grid for items,loaded from a child form on key press.
keypress code in parent:
C#
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
      {
          if (keyData == (Keys.F11))
          {
             childform obj = new childform ();
               obj.ShowDialog();
             //////////Dt_sel_item contains the selected item from child
            DataTable dt = obj.Dt_sel_item;
              /////////codes.....
          }
        }

In child form there is a search control which has an after find event on that event selected item is passed to parent and child form is closed and item is added on parent grid.
C#
 void fnd_item_AfterFind(object sender, EventArgs e)
        {

            if (this.fnd_item.ControlValue != string.Empty)
            {
/////////////dt_find_fill ,datatable having item details
//////////fnd_item ,search control
                DataTable dt_item_filter = dt_find_fill.Copy();
                dt_item_filter.DefaultView.RowFilter = "item_id=" + this.fnd_item.ControlValue;
                dt_item_filter = dt_item_filter.DefaultView.ToTable();
                dt_sel_item = dt_item_filter.Copy();
                this.Close();
            }
           
        }

if i select item in search control of child form using mouse click,everything works fine.
i have added code to set focus on qty field of parent for the selected item using below code in the parents ProcessCmdKey event

C#
try
                    {
//////////keyglobalRow global int value to store row index
                        keyglobalRow = grd_item.Rows.Count - 2;
                    }
                    catch { keyglobalRow = 0; }
                ////////////grd_item name of parent grid
///////////////////////cell[5] position of qty where i am setting focus
                    grd_item.CurrentCell = grd_item.Rows[keyglobalRow].Cells[5];
                    grd_item.Rows[keyglobalRow].Cells[5].Selected = true;

If i use enter key on search control of child for selection focus of the parent grid after loading item proceeds to one column.
i think the parent form grids enter key event is trigg
C#

ered .how can i restrict that only in this event handler,client need to move through columns in grid using tab and enter key.
plz share ur valuable suggestions
Posted

1 solution

I have added following code in child forms onload event and now its working
//////////fnd_item , is the search control
C#
fnd_item.SmartTab = false;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900