How do you search a datagridview?

Posted on 2007-10-12
Last Modified: 2013-11-26
I am building a Windows Application that gets multiple folders under another folder and puts them into a datagridview.

For example:

I find all folders under c:\inetpup\www\ but do not retrieve their subfolders.
This is put in a datagridview with a checkbox to it.
I have a ok button.

When the ok button gets pressed a function runs with the checked folders only.

I need to update the folders frequently as the software I use in the folders updates.

I somtimes just want to search for the version number or the folder name and have the datagridview go directly to the search query without changing any data within the data grid view.

I want to beable to just start typing or do a ctrl+F. which I already have functions for.

but I cannot seem to figure out how to search a datagrid.

here is my page load

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        Dim d As DirectoryInfo
        Dim rowcount As Integer = 0
        Dim ofs As New DirectoryInfo("C:\Inetpub\vhosts\")
        For Each d In ofs.GetDirectories
            rowcount += 1
        Dim directoryParts() As String
        Dim rowArray As Integer
        Dim DNNVersion As String = "0.0.0"
        For rowArray = 0 To folders.Count - 1
            directoryParts = Split(folders(rowArray).ToString, "\")
            currentDir = " C:\Inetpub\vhosts\" & directoryParts(0).ToString & "\httpdocs"
            If GetFolderStatus(currentDir) = KeyFolderStatus.MissingConfigFile Or GetFolderStatus(currentDir) = KeyFolderStatus.NoFolder Or GetFolderStatus(currentDir) = KeyFolderStatus.InvalidFolder Then
                strDatabaseVersion = "00.00.00"
                xmlConfigNew.Load(currentDir & "\web.config")
                xmlnewAppSettings = xmlConfigNew.SelectSingleNode("//appSettings")
                If Not xmlnewAppSettings Is Nothing Then
                    xmlnewNode = xmlnewAppSettings.SelectSingleNode(("//add[@key='SiteSqlServer']"))
                    If Not xmlnewNode Is Nothing Then
                        ConnectionString = xmlnewNode.Attributes.Item(1).Value.ToString
                        Dim reader As SqlDataReader = Nothing
                        Dim conn As SqlConnection = Nothing
                        Dim cmd As SqlCommand = Nothing
                        Dim sql As String = Nothing

                            Dim dr As IDataReader = GetDbVersion()
                            If dr.Read Then
                                strDatabaseVersion = Format(dr("Major"), "00") & "." & Format(dr("Minor"), "00") & "." & Format(dr("Build"), "00")
                            End If
                        Catch ex As Exception
                            strDatabaseVersion = "00.00.00"
                        End Try
                    End If
                End If
            End If
            Me.DataGridView1.Rows.Add(False, directoryParts(0).ToString, strDatabaseVersion)
    End Sub

Question by:wilecoyte78
    LVL 16

    Accepted Solution

    your searching the reader, not the grid, you have to refresh the grid with reader search result.

    Author Comment

    This is what my datagrid view looks like except the false is a checkbox:
    Selected       folder                                                    Version
    FALSE                          04.05.05
    FALSE                          04.05.05
    FALSE                   04.05.05
    FALSE                         04.05.03
    FALSE                         04.05.05
    FALSE      04.05.05
    FALSE      04.05.04
    FALSE                            04.05.03

    I want to beable to search this by folder or the version of the database. The folders are bought in by a direcotry and ther version is brought in by a database.

    Author Comment

    I also do not want to refresh the grid. I just want the scroll bar to go to the position of the folder or the version and possibly highlight the row.

    Author Comment

    One other thing. It is more important to search by folder name because most of my search is to find the new folder I just added to the directory.

    Author Comment

    Here is the solution I found on my own....:

        Private Sub FindToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FindToolStripMenuItem.Click
            SearchString = UCase(Trim(InputBox("Search for", "Find")))
            Dim datarowcount = DataGridView1.RowCount
            Dim x = 0
            For x = 0 To datarowcount - 1
                If DataGridView1.Item(1, x).Value.ToString = SearchString Then
                    DataGridView1.Item(1, x).Selected = True
                    DataGridView1.FirstDisplayedScrollingRowIndex = x
                End If

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…
    This Micro Tutorial will teach you how to reformat your flash drive. Sometimes your flash drive may have issues carrying files so this will completely restore it to manufacturing settings. Make sure to backup all files before reformatting. This w…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now