Click here to Skip to main content
14,545,256 members
Rate this:
Please Sign up or sign in to vote.
See more:
How can i select right side of currentcell and fill combobox when first combobox value changed

What I have tried:

Private Sub ODEME_BILGILER_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles ODEME_BILGILER.CellValueChanged
        If ODEME_BILGILER.Rows.Count <= 1 Then Exit Sub
        If e.ColumnIndex = 0 Then
            Dim Row As DataGridViewRow = ODEME_BILGILER.Rows(e.RowIndex)
           
            ODEME_BILGILER.CurrentCell = ODEME_BILGILER.Rows(e.RowIndex).Cells(2)
            Row.Cells(e.RowIndex).Selected = True
            Row.Cells(1).Value = Row.Cells(0).Value
      
        End If
    End Sub
Posted
Updated 19-May-20 21:31pm
v2
Comments
Ralf Meier 19-May-20 5:20am
   
Sorry ... with this less information it's impossible for me to imagine what you try to achieve ...
You should improve your question "a little bit" ...
Member 14588284 19-May-20 6:48am
   
shortly
i want select right cell when combobox changed in datagirdview
Maciej Los 19-May-20 15:44pm
   
Use "Reply" widget to post reply (on the right side of nick/login).
Maciej Los 19-May-20 15:48pm
   
Can you explain what "right cell" means?
Member 14588284 20-May-20 1:16am
   
Realy you dont unserstand this?
its pretty simple question!
in datagridview i want select right cell of currentcell

Normaly when i change currentcell value then cursor selecting under of the currentcell


Maciej Los 20-May-20 2:28am
   
Please, see my answer.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

If you would like to select "right cell" (my best guess: on the right side of current cell), you need to set DataGridView.CurrentCell Property (System.Windows.Forms) | Microsoft Docs[^]
Get and Set the Current Cell in DataGridView Control - Windows Forms | Microsoft Docs[^]

[EDIT]
OK, seems you want to change Enter key behaviour... I'd suggest to use KeyUp event.

Private Sub DataGridView1_KeyUp(sender As Object, e As KeyEventArgs) Handles DataGridView1.KeyUp
    If Label1.Text = "0" Then Exit Sub

    If e.KeyCode <> Keys.Enter Then Exit Sub
    Dim dgc As DataGridViewCell = DataGridView1.CurrentCell
    If dgc Is Nothing Then Exit Sub


    Dim c As Integer = dgc.ColumnIndex + 1
    Dim r As Integer = dgc.RowIndex - 1
    If c > DataGridView1.Columns.Count - 1 Then c = 0 : r += 1
    If r < 0 Then r = 0

    dgc = DataGridView1(c, r)
    If dgc Is Nothing Then Exit Sub

    Me.DataGridView1.CurrentCell = dgc
    Me.DataGridView1.CurrentCell.Selected = True
End Sub


You can create custom DataGridView control based on existsing one and then change Enter key behaviour in OnKeyUp event. See: Enter Key in DataGridView : C# 411[^]
   
v3
Comments
Ralf Meier 20-May-20 2:58am
   
Hy Maciej,
I'm very impressed of your ability of imagination to understand what "could be" meant by this question - or do you have a better glas-bowl than me ...? ;-)
+5 for this guess ...

To complete your answer I would first check if there is a cell right to the CurrentCell before trying to select it.
Maciej Los 20-May-20 4:12am
   
Thanks, Ralf.
I'm not sure i understand OP well, but it was worth to try answer...

As to the selecting cell - good point!
Member 14588284 20-May-20 3:10am
   
https://yadi.sk/d/0_1eEcx26yNzZw

i tryed codes but now currentcell is right (side)+down (side) of currentcell

i added a simple file, can you help on this?

Thanks for all
Ralf Meier 20-May-20 5:19am
   
You should better improve your question with the (new) code-snippet.
Which Event did you have chosen for your action ...?
Member 14588284 20-May-20 5:29am
   
i add a file in yandisk
https://yadi.sk/d/0_1eEcx26yNzZw

Did you look at file?
Ralf Meier 20-May-20 5:43am
   
No ... because it's a bit problematically in the office (where I am) ...
Therefore I suggested it the other way round ... and I think this will also be the right way ...
Maciej Los 20-May-20 6:33am
   
Take a look at updated answer.
Next time, please be more specific and provide more details... In this case it would be enough to provide complete code of event you've used in your form.
Member 14588284 20-May-20 6:46am
   
thank you so much.

it will be useful for me
Maciej Los 20-May-20 6:53am
   
You're very welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100