Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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



1 solution

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.

VB.NET
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[^]
 
Share this answer
 
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?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900