473,394 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Problem Of Custome DGV Not Allow Set Focus To Next Control On Enter Key Press

maheshwag
I have Following Custom DGV:
Expand|Select|Wrap|Line Numbers
  1. public class MyDataGridView : DataGridView
  2.     {
  3.         protected override bool ProcessDialogKey(Keys keyData)
  4.         {
  5.             Keys key = (keyData & Keys.KeyCode);
  6.             if (key == Keys.Enter)
  7.             {
  8.                 Tab(keyData);
  9.                 return true;
  10.             }
  11.             return base.ProcessDialogKey(keyData);
  12.         }
  13.         protected override bool ProcessDataGridViewKey(KeyEventArgs e)
  14.         {
  15.             if (e.KeyCode == Keys.Enter)
  16.             {
  17.                 Tab(e.KeyData);
  18.                 return true;
  19.             }
  20.             return base.ProcessDataGridViewKey(e);
  21.         }
  22.         private void Tab(Keys KeyData)
  23.         {
  24.             Point cca = CurrentCellAddress;
  25.             bool Forward = ((KeyData & Keys.Shift) != Keys.Shift);
  26.             if (Forward)
  27.                 if (cca.Y == Rows.Count - 1)            // last row?
  28.                     if (cca.X == Columns.Count - 1)     // last column?
  29.                         ToNextControl(Forward);
  30.                     else
  31.                         ProcessTabKey(KeyData);
  32.                 else
  33.                     ProcessTabKey(KeyData);
  34.             else
  35.                 if (cca.Y == 0)         // first row?
  36.                     if (cca.X == 0)     // first column?
  37.                         ToNextControl(Forward);
  38.                     else
  39.                         ProcessTabKey(KeyData);
  40.                 else
  41.                     ProcessTabKey(KeyData);
  42.         }
  43.  
  44.         /// <summary>
  45.         /// Go to the next control, forward or backword. This does not support
  46.         /// wrapping from the first to the last or the last to the first.
  47.         /// </summary>
  48.         /// <param name="Forward">Whether to go forward</param>
  49.         private void ToNextControl(bool Forward)
  50.         {
  51.             Control c = Parent.GetNextControl(this, Forward);
  52.             while (c != null && !c.TabStop) // get next control that is a tabstop
  53.                 c = Parent.GetNextControl(c, Forward);
  54.             if (c != null)
  55.                 c.Select();
  56.         }
  57.     }
  58.  
The Same work well on normal it's allow focus on next control at enter keypress but it's not work if you set AllowUserToAddRows=false on databound mode. The exact problem creates when you edit last column's cell value and press enter it's not allow to set focus on next control.

How to overcome from this?. how to solve the issue?
Aug 6 '11 #1
0 1197

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Robert Mark Bram | last post by:
Hi All, >From an event handler attached to a control that has a tab index, is it possible to find the next control in the tab order - and then focus() on it? I am having a bit of trouble with...
6
by: Terry | last post by:
I have a form which is displayed in Datasheet View and would prefer it if, when entering data, I could use the keyboard as I would when entering data into a Datasheet. Is it possible when...
16
by: MLH | last post by:
In Access 97 and Access 2.0 applications, if a command button has the focus, the spacebar will 'PRESS" the key. How does one go about disabling this annoying BEATURE?
3
by: Keith Smith | last post by:
Is there an easy way to make the {Enter} key take the cursor to the next control without using a KeyDown event on each control?
2
by: Mad Scientist Jr | last post by:
I have autopostback turned on for Textbox1. When the user tabs out of it, the codebehind recalculates some other fields based on its value, and the user should be able to start typing a value in...
4
by: chreo | last post by:
I assume that it is not hard problem. I would like user to only click in datagrid to select whole row - DONE I would like user to select whole row using UP and DOWN arrows. - DONE. And I would...
3
by: chreo | last post by:
Hello. I have datagrid. I found code to select all row in data grid (by mouse or arrow keys). This works great - user can select row and... ....and I want to go to next control. For...
4
by: Vayse | last post by:
I have a text box, with a command button next to it. When the button is pressed, I want to run some code. Then pass the focus to the next control. How do I do this? Thanks Vayse
2
by: pemigh | last post by:
Client's fingers have been well trained on another application to wrap lines by hitting shift-enter, and wants the same in Access application. Changing "enter key behavior" for controls is not...
4
by: Benson | last post by:
I want to use code to move focus from the current control to the next control (don't know the control name). Example, there are texbox A and B, and a button. The current focus is on A. When I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.