Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

filter DataGridView

Last post 07-08-2008 4:15 AM by blaknite. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-06-2008 6:30 AM

    • blaknite
    • Top 500 Contributor
    • Joined on 12-01-2003
    • Addicted Member
    • Points 940

    filter DataGridView

     I am currently running VS2008 and this is the following code I use to populate 2 DataGridView's on my application......

    Imports System.Data
    Imports System.Data.OleDb
    
    Public Class Form1
        Dim strTestConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\Game.mdb"
        Dim strSQLSelect1 As String = "SELECT * FROM Armor"
        Dim strSQLSelect2 As String = "SELECT * FROM Player"
        Dim ArmorDataAdapter As New OleDbDataAdapter(strSQLSelect1, strTestConnection)
        Dim PlayerDataAdapter As New OleDbDataAdapter(strSQLSelect2, strTestConnection)
        Dim TestDataSet As New DataSet()
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ArmorDataAdapter.Fill(TestDataSet, "Armor")
            PlayerDataAdapter.Fill(TestDataSet, "Player")
            DataGridView1.DataSource = TestDataSet
            DataGridView1.DataMember = "Armor"
            DataGridView2.DataSource = TestDataSet
            DataGridView2.DataMember = "Player"
        End Sub
    End Class

     My question is this... I want to add either a textbox and use its textchanged event?

    OR Add a textbox and a button, when the user clicks the button the code I want to run will run....

    I want to be able to use this textbox to sort through the records in the DGV ....

    FOR EXAMPLE  If my stored records are JAMES, JASON, JACK

    A user types "JA" into the textbox and all the records stay because all the names start with JA

    If they go one step further and type "JAM" into the textbox, only JAMES' record will show in the DGV and the rest will be invisible.

    when the textbox = Nothing ....... all records return......  How do I do this?

    I have seen filters like this created in previous versions, just not sure how to update them.

    NOTE: Although the above code populates 2 DGV's, the filter itself, need only apply to one as there will only be one DGV, I was just messing around with a tutorial on how to load 2 DGV's from one dataset I did search the internet for the answer to this, but none quite gave me the answer I was looking for.

    • Post Points: 10
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 07-06-2008 10:57 PM In reply to

    • konikula
    • Top 50 Contributor
    • Joined on 12-19-2005
    • Czech Republic
    • Guru
    • Points 3,725

    Re: filter DataGridView

    use datatable instead of dataset, there you can add filter to it which is immediately through datagrid/view.
    for show all you only set filter to empty text, and for JOH found JOHN use "column LIKE "%JOH%"

    you can look at my Support.lDataTable.SearchDT function for inspiration

    I can advice you, but I have many questions too. support.vb
    • Post Points: 10
  • 07-08-2008 12:09 AM In reply to

    • TimL
    • Top 100 Contributor
    • Joined on 07-02-2007
    • United Kingdom
    • Fanatic Member
    • Points 1,540

    Re: filter DataGridView

    Just to slightly extend upon konikulas idea of using the DataTable.Select method, perhaps another possibility is to use a dataview?

    http://msdn.microsoft.com/en-us/library/system.data.dataview.aspx

     

    • Post Points: 5
  • 07-08-2008 4:15 AM In reply to

    • blaknite
    • Top 500 Contributor
    • Joined on 12-01-2003
    • Addicted Member
    • Points 940

    Re: filter DataGridView

    thank you both for the suggestions ....

    I will read up on both and reply back if I was able to solve it :)

    • Post Points: 5
Page 1 of 1 (4 items)