Jump and mark row when typing in datagridview (like you can do in a listbox)

I want to be able to click into a datagridview and based on one of the columns (productname), and then for example type letter "D" or maybe "DE", and then jump to the first row that contains "D" or "DE".

In a Listbox this works without no extra code, how to do this in a DataGridview in VB.NET?
Who is Participating?
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Hi.. thorv71

As far as i know
there is no such a property (option) for datagridview..
Usually for DGV we use the BindingSource.Filter method or the DataView RowFilter in accordance with TextChange Event of a TextBox..
If something like this reaches your needs please ask further to provide you some code...

Maybe there is a way to achieve that but i think you might override the standard DGV or write some extra code

thorv71Author Commented:
I don't want to use a textbox, because her it is four DGVs side by side, and where the first DGVs choice filter the second and then so.. for the third an fourth.

So if i go to the second DGV and type "DE" the result for the DGV has to stay the same, "all" I want is that the the DGV jump and select the first row that start with f.ex "DE" if it exists in the row.

Some one that has some code snip for this ?  :-)
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

thorv71Author Commented:
The Code in the article was a little bit to complex for me, I resolved this with a less code. Only this code just allows me to use one letter, so if you know how I can retrive more then one letter using e.KeyChar or something like that, I will be very pleased :-)

This is my Simple Code:  :-)

        Dim i As Integer
        Dim keypresset As String = ""
        Dim prg_navn As String = ""
        Dim prg_navn_first_letter As String = ""
        keypresset = e.KeyChar

        For Each RW As DataGridViewRow In Me.DataGridView_PRG.Rows

            i = RW.Index
            prg_navn = RW.Cells("prg_navn").Value.ToString
            prg_navn_first_letter = Mid(prg_navn, 1, 1)

            If keypresset = LCase(prg_navn_first_letter) Then
                Me.DataGridView_PRG.Rows(i).Selected = True
                Me.DataGridView_PRG.CurrentCell = DataGridView_PRG.Rows(i).Cells("prg_navn")
                Exit For
            End If
What event are you handling for this code, which is generating the e.KeyChar property? KeyChar is only going to get one letter, but you can potentially combine additional letters. You'd need to define the match string at the class rather than method level (so it survives multiple calls). It would need to be blanked out when the form displays, or when entering the DataGridView.

Or you could just use the code in the article. You'd only need to alter the Load event handler with your DGV name, etc. So what if it has some stuff you don't understand? As long as it does what you want, there's really no reason to fear. I've gotten code segments from here and elsewhere on the Web, and frankly I don't understand how all of them work, but work they do. But I understand if you want to use a more standardized approach.
thorv71Author Commented:
The case is that I need to use this code in a solution where it is over 25 DGVs, and I dont like to use more code than nesseary to do this event, and I like to understand the code 100% i case of problem in the future.

I have talk to me customer now, and they just need to use the first letter, so the code that I wrote works, but thanks for any help anyway :-)
I would have been happy to talk you through the code, but if you're all set with what you have, that's your choice. Thanks for the points.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.