datagridview problem
-
hi all, I have problem.in window application i am using datagrid veiw control.in this control cursor is moving to down cell when we press "enter key "(keyboard) .but i want to move to next cell(beside) of current cell when we press enter key buttone.how can we do this . please help me
-
hi all, I have problem.in window application i am using datagrid veiw control.in this control cursor is moving to down cell when we press "enter key "(keyboard) .but i want to move to next cell(beside) of current cell when we press enter key buttone.how can we do this . please help me
Hi, The behavior you have noticed is the default behavior of the grid. In order to implement the desired behavior you need to sub class the DataGridView controls and override/overload ProcessDialogKey and ProcessDataGridViewKey functions. Below is the code snippet for the same. ------------------------------------------------------------------------- BEGIN CODE Public Class dgv Inherits DataGridView Protected Overloads Overrides Function ProcessDialogKey(ByVal keyData As Keys) As Boolean Dim key As Keys = (keyData And Keys.KeyCode) If key = Keys.Enter Then Return Me.ProcessRightKey(keyData) End If Return MyBase.ProcessDialogKey(keyData) End Function Protected Overloads Overrides Function ProcessDataGridViewKey(ByVal e As KeyEventArgs) As Boolean If e.KeyCode = Keys.Enter Then Return Me.ProcessRightKey(e.KeyData) End If Return MyBase.ProcessDataGridViewKey(e) End Function End Class END CODE ------------------------------------------------------------------------- For more details please visit the following link: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=157055&SiteID=1[^] I hope this helps :) .
Regards, John Adams ComponentOne LLC
-
Hi, The behavior you have noticed is the default behavior of the grid. In order to implement the desired behavior you need to sub class the DataGridView controls and override/overload ProcessDialogKey and ProcessDataGridViewKey functions. Below is the code snippet for the same. ------------------------------------------------------------------------- BEGIN CODE Public Class dgv Inherits DataGridView Protected Overloads Overrides Function ProcessDialogKey(ByVal keyData As Keys) As Boolean Dim key As Keys = (keyData And Keys.KeyCode) If key = Keys.Enter Then Return Me.ProcessRightKey(keyData) End If Return MyBase.ProcessDialogKey(keyData) End Function Protected Overloads Overrides Function ProcessDataGridViewKey(ByVal e As KeyEventArgs) As Boolean If e.KeyCode = Keys.Enter Then Return Me.ProcessRightKey(e.KeyData) End If Return MyBase.ProcessDataGridViewKey(e) End Function End Class END CODE ------------------------------------------------------------------------- For more details please visit the following link: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=157055&SiteID=1[^] I hope this helps :) .
Regards, John Adams ComponentOne LLC
Thank you sir for sending solution.but i am using c# in my windows application.in that i have taken datagridview control in form9 and where i can declare this class(your code) .how can we access that class please send clearly sir.i have been trying to solve this problem. thank you sir. Regards Obalesu
-
Thank you sir for sending solution.but i am using c# in my windows application.in that i have taken datagridview control in form9 and where i can declare this class(your code) .how can we access that class please send clearly sir.i have been trying to solve this problem. thank you sir. Regards Obalesu
thank you jhon for your code .it is working.but cursor does not gone to next row first cell when the cursor is in last cell of the currentrow when we press enter key.and i am facing another problem is i was trying to check the data entered by us in datagridview to database table.means datagridview first column name "x".i want check the x values to database table values if the data is already exist in database table at that time i want to show an error msg in message box.after that the cursor must be in the error cell.but the cursor moves to next cell.if error occurs the cursor must be in the error cell only.if u have any idea send me. thank you sir. regards Obalesu.nagamalli