none
Filter grid based off form ID field RRS feed

  • Question

  • I know this is going to be a newbie question, and thats fine, I am learning, lol.

    I have a form with a field txtbx_SystemID and I would like my grid (grid_components) to filter based off that ID. I dont know how to accomplish this in VB.net, but I was hoping it would be a filter where me.txtbx_systemid.text = me.grid_components.column1 or something like that?

    Monday, March 20, 2017 10:22 AM

All replies

  • When you are writing "grid_components", is that a GridView control or a grid tool from a 3rd-party?

    Monday, March 20, 2017 10:33 AM
  • the native gridview control in vb.net
    Monday, March 20, 2017 10:48 AM
  • So you want to filter the rows of a DataGridView from a textbox field.

    How is your DataGridView populated? from a DataTable?

    can you show some code you have so we can help you in the rigth direction?

    Monday, March 20, 2017 10:58 AM
  • no code really to show, its a drag and drop grid populated with a bindingsource
    Monday, March 20, 2017 11:12 AM
  • In foxpro I could just do a select statement into a cursor and then set the cursor as the rowsource for the grid, still learning the convert over to VB.net
    Monday, March 20, 2017 11:14 AM
  • Ryan,

    You're new. A GridView is a control of asp.net for which the questions are handled in the Microsoft asp.net forum.

    http://forums.asp.net


    Success
    Cor

    Monday, March 20, 2017 12:02 PM
  • sorry cor its a DataGridView in Vb.net
    Monday, March 20, 2017 12:25 PM
  • You add a secondary query in the xsd file e.g.

    I did a LIKE condition, you can of course do a WHERE field = x

    SELECT Identifier, CompanyName, ContactName, ContactTitle, Country
    FROM     Customers
    WHERE  (ContactTitle LIKE N'%' + @ContactTitle + N'%')

    I added a TextBox to the BindingNavigator and when the user presses ENTER invoke the query above.

    Note your BindingSource has many properties and methods to assist working your data along with the abilities to cast the BindingSource DataSource down to the table level to work filtering on the table's DataView.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, March 20, 2017 12:58 PM
    Moderator
  • Yea you see, likewise programming it saves a lot of time to use the correct names. 

    Now we need to know if you have used databinding. In that case you can simply use the filter property of that.

    https://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.filter(v=vs.110).aspx

    There is a sample on the bottom.

    Probably you've done it in a different way, but know that if you ask a question, we don't look through your eyes. 

    It is as asking: "Can I eat that?". If you are on a table it goes, but if you ask it on Internet in a message............................................................. You may the rest fill in yourself. 


    Success
    Cor

    Monday, March 20, 2017 1:05 PM
  • I sort of got it to work, but it appears I am always one record off when calling it from navigation buttons.

    Dim recsystemID, filterstring as String

    RecsystemID = Me.SystemID.Text

    filterstring = "SystemID = " & RecsystemID

    mainsystembindingsource.filter = filterstring

    • Proposed as answer by Cor Ligthert Monday, March 20, 2017 6:14 PM
    Monday, March 20, 2017 6:06 PM
  • I sort of got it to work, but it appears I am always one record off when calling it from navigation buttons.

    Dim recsystemID, filterstring as String

    RecsystemID = Me.SystemID.Text

    filterstring = "SystemID = " & RecsystemID

    mainsystembindingsource.filter = filterstring

    Yes this should do it with a bound datagridview. Can of course also in one code line, but to try this is mostly the best way. 

    Success
    Cor

    Monday, March 20, 2017 6:14 PM
  • I found the issue with the records appearing to show one record behind, I am running the code within navigation buttons using the Binding Navigator.
    Wednesday, March 22, 2017 12:27 PM