[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1453
  • Last Modified:

How do you search a datagridview?

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
            Me.folders.Add(d.Name)
            rowcount += 1
        Next
        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"
            Else
                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

                        Try
                            Dim dr As IDataReader = GetDbVersion()
                            If dr.Read Then
                                strDatabaseVersion = Format(dr("Major"), "00") & "." & Format(dr("Minor"), "00") & "." & Format(dr("Build"), "00")
                            End If
                            dr.Close()
                        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)
        Next
    End Sub


0
wilecoyte78
Asked:
wilecoyte78
  • 4
1 Solution
 
SQL_SERVER_DBACommented:
your searching the reader, not the grid, you have to refresh the grid with reader search result.
0
 
wilecoyte78Author Commented:
This is what my datagrid view looks like except the false is a checkbox:
Selected       folder                                                    Version
FALSE      amarilloautoglass.net                          04.05.05
FALSE      amarilloroofing.net                          04.05.05
FALSE      atlanta-carpetcleaning.com                   04.05.05
FALSE      atlanta-landscaping.com                         04.05.03
FALSE      atlantacriminallawyer.net                         04.05.05
FALSE      atlantapersonalinjurylawyer.net      04.05.05
FALSE      atlantapestcontrolcompany.com      04.05.04
FALSE      atlantaroofing.net                            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.
0
 
wilecoyte78Author Commented:
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.
0
 
wilecoyte78Author Commented:
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.
0
 
wilecoyte78Author Commented:
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
        Next
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now