Avatar of venkataramanaiahsr
venkataramanaiahsr

asked on 

Searching text in datagridview column in vb.net

I have a datagridview with list of items in the column. I have a text box where i type a search string.

Currently i have implemented a method which is working in almost all scenarios except the following one
  Suppose a list contains a 24hrs S Creatinine and S creatinine and when i type a  creatinine
   it searches first occurance of the string and highlights it.

My code for the same is as below.

Private Sub TextBox9_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox9.TextChanged



        dgvOIList.ClearSelection()


        dgvOIList.Sort(dgvOIList.Columns("Oiname"), System.ComponentModel.ListSortDirection.Ascending)
        Dim rowindex As Long = GridRowLocator(dgvOIList, "Oiname", TextBox9.Text.ToUpper, "Text")
        If rowindex = -1 Then Exit Sub

        dgvOIList.Rows(rowindex).Selected = True
        dgvOIList.FirstDisplayedScrollingRowIndex = rowindex

        dgvOIList.CurrentCell = dgvOIList.Item("Oiname", CInt(rowindex))
        dgvOIList.CurrentCell.Selected = True


    End Sub




Public Function GridRowLocator(ByVal dtg As DataGridView, ByVal ColumnName As String, _
                                         ByVal ValueToSearch As String, ByVal strSearchType As String) As Long


        Dim CurrentRowIndex As Long = -1
        Try


            Select Case strSearchType.ToUpper

             

                Case "TEXT"

                    If dtg.Rows.Count > 0 Then
                        For i = 0 To dtg.Rows.Count - 1
                            If                  
                  dtg.Rows(i).Cells(ColumnName).Value.ToString.Contains(ValueToSearch.ToUpper) = True Then
                                CurrentRowIndex = dtg.Rows(i).Index
                                Exit For
                            End If
                        Next
                    End If


            End Select
        Catch ex As Exception
            MsgBox("Error: " & ex.Message, MsgBoxStyle.Information)
        End Try


        Return CurrentRowIndex

    End Function

My requirement is all the list items containing the search string should be grouped together one below another.  Can some expert pls advise on how to do this.
Visual Basic.NET

Avatar of undefined
Last Comment
venkataramanaiahsr
Avatar of Jerry Miller
Jerry Miller
Flag of United States of America image

Rather than build something yourself, have you looked at the Ajax Control Toolkit? The AutoComplete Extender does this very well.

http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx
ASKER CERTIFIED SOLUTION
Avatar of venkataramanaiahsr
venkataramanaiahsr

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of venkataramanaiahsr
venkataramanaiahsr

ASKER

It is windows forms application. I could solve the said problem in another way by using bindingsource filter method.
Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo