Values only change when i use the mouse

mustish1
mustish1 used Ask the Experts™
on
Hi guys: Is there any way I can change these values by means of using the arow keys as right now they only change in the textboxes when I use the mouse.

Thanks

s
    Public Sub Get_Weights(Active_Status)
        DataGridView1.DataSource = "null"
        sDataBaseString(2) = "data source=175.16.64.3;user id=sa;password=;initial catalog=processtwo"
        Dim strConnection As String = sDataBaseString(2)
        Dim cn As SqlConnection = New SqlConnection(strConnection)
        Dim bSource As New BindingSource
        DataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        Try
            cn.Open()
            query = "select BarcodeType as Tank, Active as Active, Description as Description, ContractWeight as 'Contract Weight', ComponetWeight as 'Component Weight', WatchTolerance as 'Watch Tolerance', LimitTolerance as 'Limit Tolerance', convert(float, ComponetWeight)+convert(float, ContractWeight) as 'Target Weight' from Weights " & Active_Status
            command = New SqlCommand(query, cn)
            sda.SelectCommand = command
            sda.Fill(dbDataSet)
            bSource.DataSource = dbDataSet
            DataGridView1.DataSource = bSource
            'sda.Update(dbDataSet)
            command = New SqlCommand(query, cn)
            reader = command.ExecuteReader
        Catch ex As SqlException
            MessageBox.Show(ex.Message)
        Finally
            cn.Dispose()
        End Try

    End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Database and Application Developer
Commented:
I have tested the following and it work but you need to use the concept and make it work for your project:

Private Sub TblCustomersDataGridView_RowEnter(sender As Object, e As DataGridViewCellEventArgs) Handles TblCustomersDataGridView.RowEnter
        FireMyEvent(Me.TblCustomersDataGridView.Rows(e.RowIndex).Cells(1).Value)
    End Sub
    Private Sub FireMyEvent(strTemp As String)
        Me.CityTextBox.Text = strTemp
    End Sub
    Private Sub TblCustomersDataGridView_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles TblCustomersDataGridView.CellClick
        FireMyEvent(Me.TblCustomersDataGridView.Rows(e.RowIndex).Cells(1).Value)
    End Sub

Open in new window


You have CellClick event working for you now via mouse click. Is this correct?

If so, make a new sub (I have called it FireMyEvent in my sample). And move your existing code from CellClick to FireMyEvent . Of course you need to call  FireMyEvent from your existing CellClick with required parameters.

Test it and make sure it works as before just using mouse click.

Now, activate your datagridview RowEnter event.  Then add to this event the FireMyEvent method the same as the one you just added to CellClick event.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial