We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Moving inside a control using <- or -> in a grid

Hi, I use a GDBG and i have a combobox control as a control in one of the cells. The problem is that if i''m writting something in the combobox and i use the cursor keys <- (left) or -> (right), the focus goes to the previous or next cell instead of moving the cursor inside the combobox. How can i make the key event to target the combobox instead of the datagrid? Thank you Borja

2 Replies

AD Administrator Syncfusion Team May 30, 2006 04:06 AM UTC

Hi Borja, There is no built-in support for this. Could you try this code in Grid Style''s Control.KeyDown event. e.Style.Control.KeyDown +=new KeyEventHandler(Control_KeyDown); private void Control_KeyDown(object sender, KeyEventArgs e) { ComboBox combo = sender as ComboBox; if(combo.Focused) { if(e.KeyData == Keys.Left) { this.gridDataBoundGrid1.CurrentCell.MoveLeft(); e.Handled = true; } else if(e.KeyData == Keys.Right) { this.gridDataBoundGrid1.CurrentCell.MoveRight(); e.Handled = true; } } } Here is a sample. http://www.syncfusion.com/Support/user/uploads/ComboGDBG_c16e5602.zip Let me know if this helps. Best Regards, Haneef


BO Borja May 30, 2006 08:01 AM UTC

Hi Haneef, Actually my problem is the other way around: the combo has the focus and when i press -> (or <-) i want the cursos to move right (or left) in the text of the combobox, but instead of that the next (or previous) cell gets the focus. I''ve a few tests implementing the combo''s KeyDown event as in the example, but when these keys (any special key) are pressed this event doesn''t get fired (grid_keydown is fired instead). Finally i''ve got a solution this way (implementing grid''s KeyDown event instead of combo''s KeyDown event): void gridDataBoundGrid1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (oCombo.Focused) { int position = oCombo.SelectionStart + oCombo.SelectionLength; if (e.KeyData == Keys.Left) { oCombo.SelectionLength = 0; if (position > 0) oCombo.SelectionStart = position - 1; e.Handled = true; } else if (e.KeyData == Keys.Right) { oCombo.SelectionLength = 0; if (position < oCombo.Text.Length) oCombo.SelectionStart = position + 1; else oCombo.SelectionStart = position ; e.Handled = true; } } } Thank you

Loader.
Live Chat Icon For mobile
Up arrow icon