none
Search opposite value datagridview RRS feed

  • Question

  • hi

    how to  Search opposite value in datagridview

    with tow value opposite  good & bad

    example

    textseach="Ramy good ali"

    opposite value =result cell "Ramy bad ali"  'bad

    easy search in datagridview

     For i As Integer = 0 To DATAG_CLIEN.RowCount - 1
                If DATAG_CLIEN.Rows(i).Cells(1).Value.ToString.Contains(textseach.text) Then
    
                End If
            Next


    • Edited by monemas Thursday, December 12, 2019 10:29 PM
    Thursday, December 12, 2019 10:28 PM

Answers

  • Hi,

    It is recommended that you replace the string you want to query, and then find the replaced string in the DataGridView.

    Is this effect that you want?

    Imports System.Data.OleDb
    
    Public Class Form3
        Dim path As String = "D:\Student.xls"
        Dim constr As String = "provider=Microsoft.Jet.OLEDB.4.0;" + "data source=" + path + ";Extended Properties=Excel 8.0;"
    
        Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Using conn As New OleDbConnection(constr)
                conn.Open()
                Using cmd As New OleDbDataAdapter("select * from [Sheet1$]", conn)
                    Dim ds As New DataSet()
                    cmd.Fill(ds, "Table1")
                    Me.DataGridView1.DataSource = ds
                    Me.DataGridView1.DataMember = "Table1"
                End Using
            End Using
            DataGridView1.AllowUserToAddRows = False
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            ListBox1.Items.Clear()
            'ListBox1.Items.Add(DataGridView1.Columns(0).HeaderText & "   " & DataGridView1.Columns(1).HeaderText & "   " & DataGridView1.Columns(2).HeaderText)
            Dim SearchText As String = TextBox1.Text
            If SearchText.Contains("good") Then
                SearchText = SearchText.Replace("good", "bad")
            ElseIf SearchText.Contains("bad") Then
                SearchText = SearchText.Replace("bad", "good")
            End If
    
            For Each row In DataGridView1.Rows
                If row.Cells(1).Value.ToString.Trim = SearchText Then
                    ListBox1.Items.Add(row.Cells(0).Value & "   " & row.Cells(1).Value & "   " & row.Cells(2).Value)
                End If
            Next
        End Sub
    End Class

    If you just want to query the records in the DataGridView, you can do it like above. Another method is to use ADO.NET to find, then populate the DataSet and display it on the DataGridView, that's well to.

    In addition, it is recommended that you do not only give screenshots when giving the data. For us, it is time-consuming to reproduce your data and then help you solve the problem.

    Hope it be helpful.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, December 13, 2019 6:21 AM
    Moderator

All replies

  • You are posting an Image again!

    Do you expect others to re-type your data?


    Regards Les, Livingston, Scotland

    Thursday, December 12, 2019 10:36 PM
  • You are posting an Image again!

    Do you expect others to re-type your data?


    Regards Les, Livingston, Scotland

    This is an example of the same columns with DatagridView and the same data.
    What I want is the search method

    Thursday, December 12, 2019 11:26 PM
  • You are posting an Image again!

    Do you expect others to re-type your data?


    Regards Les, Livingston, Scotland

    This is an example of the same columns with DatagridView and the same data.
    What I want is the search method

    Until you post a text version of the data which you show as an image, I will not go any further with you. You must post a TEXT version of the data.

    Regards Les, Livingston, Scotland

    Thursday, December 12, 2019 11:59 PM
  • hi

    how to  Search opposite value in datagridview

    with tow value opposite  good & bad

    example

    textseach="Ramy good ali"

    opposite value =result cell "Ramy bad ali"  'bad

    easy search in datagridview


    WHY NOT THIS ONE?


    Regards Les, Livingston, Scotland

    Friday, December 13, 2019 12:15 AM
  • hi

    how to  Search opposite value in datagridview

    with tow value opposite  good & bad

    example

    textseach="Ramy good ali"

    opposite value =result cell "Ramy bad ali"  'bad

    easy search in datagridview


    WHY NOT THIS ONE?


    Regards Les, Livingston, Scotland

    ??? 
    I want to show all search results
    And not only one




    • Edited by monemas Friday, December 13, 2019 12:21 AM
    Friday, December 13, 2019 12:18 AM
  • WHERE?

    Regards Les, Livingston, Scotland

    Friday, December 13, 2019 1:07 AM
  • Hi,

    It is recommended that you replace the string you want to query, and then find the replaced string in the DataGridView.

    Is this effect that you want?

    Imports System.Data.OleDb
    
    Public Class Form3
        Dim path As String = "D:\Student.xls"
        Dim constr As String = "provider=Microsoft.Jet.OLEDB.4.0;" + "data source=" + path + ";Extended Properties=Excel 8.0;"
    
        Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Using conn As New OleDbConnection(constr)
                conn.Open()
                Using cmd As New OleDbDataAdapter("select * from [Sheet1$]", conn)
                    Dim ds As New DataSet()
                    cmd.Fill(ds, "Table1")
                    Me.DataGridView1.DataSource = ds
                    Me.DataGridView1.DataMember = "Table1"
                End Using
            End Using
            DataGridView1.AllowUserToAddRows = False
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            ListBox1.Items.Clear()
            'ListBox1.Items.Add(DataGridView1.Columns(0).HeaderText & "   " & DataGridView1.Columns(1).HeaderText & "   " & DataGridView1.Columns(2).HeaderText)
            Dim SearchText As String = TextBox1.Text
            If SearchText.Contains("good") Then
                SearchText = SearchText.Replace("good", "bad")
            ElseIf SearchText.Contains("bad") Then
                SearchText = SearchText.Replace("bad", "good")
            End If
    
            For Each row In DataGridView1.Rows
                If row.Cells(1).Value.ToString.Trim = SearchText Then
                    ListBox1.Items.Add(row.Cells(0).Value & "   " & row.Cells(1).Value & "   " & row.Cells(2).Value)
                End If
            Next
        End Sub
    End Class

    If you just want to query the records in the DataGridView, you can do it like above. Another method is to use ADO.NET to find, then populate the DataSet and display it on the DataGridView, that's well to.

    In addition, it is recommended that you do not only give screenshots when giving the data. For us, it is time-consuming to reproduce your data and then help you solve the problem.

    Hope it be helpful.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, December 13, 2019 6:21 AM
    Moderator