I want to enter a value into column1 only of datagridview1 then press enter. But here datagridview2 isnt displayed after edit...Further, The cell value entered is used to search the database that is bound to Datagridview2(using binding source) and then there should be results are displayed in the datagridview2 which is full row select and it is made to be visible.
The code I have put is: (thanks to dave for little help here)Private Sub DataGridView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
If e.KeyCode = Keys.Enter And DataGridView1.CurrentCell.ColumnIndex = 0 Then
e.Handled = True
DataGridView2.Visible = True
To get the results in datagridview2 according to the value entered in column1 of datagridview1 I can use tableadapter with code as something like
When I select the right item in datagridview2 and hit enter the rows of the selected should be entered automatically into column1, column2, column3, column4 and column5of datagridview1.Can anyone help..?Wednesday, December 08, 2010 8:09 PM
Doing something when you have finished entering data to a cell can be done by handling the EndEdit or CellValidating events. However I would take a different approach. Add the following class to your project
Public Class MyDataGridView Inherits DataGridView Public Event EnterPressed(ByVal sender As Object, ByVal e As KeyEventArgs) Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean If CurrentCell.ColumnIndex = 0 And keyData = Keys.Enter Then RaiseEvent EnterPressed(Me, New KeyEventArgs(Keys.Enter)) EndEdit() Return Nothing Else Return MyBase.ProcessDialogKey(keyData) End If End Function End Class
Build the project and myDataGridView will appear at the top of your toolbox. Use it instead of a normal DataGridView for the first grid. It has a new event "EnterPressed" which is raised when you press Enter in edit mode in column 0. Handle that event to show the other datagridview. Of course this won't help if the user presses Tab or clicks in another cell to end the edit.
For the other questions you should start a new thread.Wednesday, December 08, 2010 9:25 PM