Find in DataGridView

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • havana7
    New Member
    • Jul 2007
    • 13

    Find in DataGridView

    Hi people,

    with this command I can get the row index of founded records:
    i = dv.Find(txtFind .Text);
    but is there a good method that lets me show only founded records in DataGridView?

    Or is it correct to clear the DataSet, to query database and to fill DataSet with search result??? (I tried it and it works!)

    Thanx
  • havana7
    New Member
    • Jul 2007
    • 13

    #2
    What is the best way to search in a DataSet and show results???
    DataView.Find or to query DB and to fill DataSet?
    Thanx

    Comment

    • Vidhura
      New Member
      • May 2007
      • 99

      #3
      Originally posted by havana7
      What is the best way to search in a DataSet and show results???
      DataView.Find or to query DB and to fill DataSet?
      Thanx
      Use bindingsource
      BindingSource bs= new BindingSource(d ataset, "table");
      dataGridview1.d atasource=bs;


      To filter the records
      bindingSourceRo ute.Filter ="ID=20";

      Bind it again with datagridView
      dataGridview1.d atasource=bs;
      this.dataGridvi ew1.Update();

      Comment

      • radcaesar
        Recognized Expert Contributor
        • Sep 2006
        • 759

        #4
        Originally posted by havana7
        What is the best way to search in a DataSet and show results???
        DataView.Find or to query DB and to fill DataSet?
        Thanx

        Here is the best and fast one

        Private Sub btnSearch_Click (ByVal sender As System.Object, ByVal e As System.EventArg s) _
        Handles btnSearch.Click

        'Create and fill the dataset
        Dim ds As New DataSet()
        ds.ReadXml(Serv er.MapPath(".") & "\..\Xml\PartLi st.xml")

        'Set a primary Key
        ds.Tables(0).Pr imaryKey = New DataColumn() {ds.Tables(0).C olumns("partid" )}

        'Create a datarow collection
        Dim drCollection As DataRow()

        'Use the tables.select command and pass in your search criteria
        drCollection = ds.Tables(0).Se lect("manufactu rer = '" _
        & Replace(txtSear ch.Text, "'", "''") & "'")


        'Display results by looping through datarow collection
        Dim dr As DataRow
        lblResults.Text = ""
        For Each dr In drCollection
        lblResults.Text = lblResults.Text & dr.Item("partid ").ToString & ","
        Next

        'Dispose item
        ds.Dispose()
        End Sub

        Comment

        • havana7
          New Member
          • Jul 2007
          • 13

          #5
          Originally posted by Vidhura
          Use bindingsource
          BindingSource bs= new BindingSource(d ataset, "table");
          dataGridview1.d atasource=bs;


          To filter the records
          bindingSourceRo ute.Filter ="ID=20";

          Bind it again with datagridView
          dataGridview1.d atasource=bs;
          this.dataGridvi ew1.Update();
          I like very much this solution, thanx to everybody!!!

          Comment

          Working...