Controlling the taborder in a DataGridView

I'm working on an orderform with order-rows bound in a DataGridView. My first Column contains ProductNo. If the User fills out the ProductNo, Columns with description, price etc are automatically filled out. These I'd like the user to be able to skip if they've filled out the first column correctly. Under what Event can I do this? The datatable lookup is done under CellValueChanged. It seems wherever I put my code it is overridden by the DGVs own procedures.

If I put a button on the form and press it, my attached code works like a charm.



dgvOrderRow.CurrentCell = dgvOrderRow.Rows(0).Cells("txtQuantity")

Open in new window

ekenmanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ekenmanAuthor Commented:
(I've tried a timer.... it works, but naturally I'd like to avoid it....)
0
ekenmanAuthor Commented:
OK, I'm off to a meditation retreat for the rest of the week (wich I really need since I really can't solve this). I won't be able to test any solutions but I'll leave the question open and hope that it's not impossible without writing a grid my self...

Best Regards

Tomas
0
Priest04Commented:
I would make the datagridview unbound, then in a DataGridView CellEndEdit event, I would do the following:


sub dfb_CellEndEdit(......)
    if (e.ColumnIndex = 0) then
        ' do a search on a datatable (or dataview) for the ProductNo the user has typed in
        ' when record is found, manually update other cells with the values from the found reocrd
    end if
end sub

Open in new window

0
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

ekenmanAuthor Commented:
Hi Priest04,

There is no difference with bound or unbound datagrids. I've tried your solution but it is the same problem that if I set the current cell in the CellEnddit event, some event that occurs after that sets the current cell to the next one.

Thanks anyway!
0
Priest04Commented:
>> There is no difference with bound or unbound datagrids.

If you say so.

Place one datagridview on the form, add 3 columns manually, in the form load event set

dataGridView.RowCount = 5;

add this code to the datagridview_CellEndEdit()

dataGridView1.CurrentCell = dataGridView1[1, 1];

and it will always move focus to cell (1, 1)

0
ekenmanAuthor Commented:
Well, I tried that too... Although I'm running VB so the Syntax is a little bit different.

On an empty form I place a DataGridView. The instance is then called DataGridView1.

I've attached the code that is in the form. It doesn't work for me. I'm alowing adding, editing and deleting. Could this be the problem?
Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
        DataGridView1.CurrentCell = DataGridView1(1, 1)
    End Sub
 
   
    Private Sub frmPrintInvoice_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        DataGridView1.Columns.Add("Column1", "First")
        DataGridView1.Columns.Add("Column2", "Second")
        DataGridView1.Columns.Add("Column3", "Third")
        DataGridView1.RowCount = 5
 
    End Sub

Open in new window

0
ekenmanAuthor Commented:
And Priest04, about the difference with bound and unbound, I should have put it like this: as far as I can see, there is no difference when it comes to this issue... There are probably a great many differenses :)
0
Priest04Commented:
Ok, I see what you mean. In order to achieve what you want, you would need to override default behavior of Enter key. This will require to create a custom datagridview control and override ProcessDialogKey to handle enter key. Yo will need to use CustomDataGridView instead of DataGridView control whenever you need this functionality.
Public Class dgv
    Inherits DataGridView
 
    Protected Overloads Overrides Function ProcessDialogKey(ByVal KeyData As Keys) As Boolean
        Dim key As Keys = KeyData And Keys.KeyCode
 
        Select Case key
            Case Keys.Enter
                ' simulate that CTRL+ENTER is pressed, so control will not jump to cell bellow
                KeyData = KeyData Or Keys.Control
                Exit Select
        End Select
 
        Return MyBase.ProcessDialogKey(KeyData)
    End Function
 
 
End Class

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ekenmanAuthor Commented:
OK, I'll try this
0
ekenmanAuthor Commented:
Thank you so much! That does it!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.