Load different datagridview based upon what the person has entered

Code with C | Programming: Projects & Source Codes Forums C# Programming Load different datagridview based upon what the person has entered

This topic contains 2 replies, has 1 voice, and was last updated by  Ganesh 2 years, 9 months ago.

  • Author
  • #10189


    I’m currently working on an assignment for school, which involves having to make an application that retrieves data from a database and shows that data on the screen. Now I am making a kind of inventory for products and etc, and you have 3 possibilities: You can choose to search on ProductId, CustomerId and OrderId.

    How can I load a different datagridview based upon what the person has entered? I already have the code to figure out what they filled in, I simply need to know how I can manually load a datagridview on my form and add data into it.

  • #10190


    Use only one DataGridView and then use Ling to filter out the results. If you don’t need to edit/modify the results, it will be a bit easy Take a look at this link below. Basically you change the DataGridView source based on the query. So ProductId, CustomerId, and OrderId would pull from the same database, but you would use a filter to set each datasource. Let’s say you have a ComboBox you can just have the DataGridView.DataSource change depending on the ComboBox selection.

    If I have time tomorrow, I’ll put together a working sample, just let me know if you need to edit the results, because that’s more involved.


    Take a look at this for more Linq queries.


  • #10191


    Here you go. I just tested this an it worked. Use it for reference. I didn’t have a data source so I created a test class. Could be a little cleaner, but I’m pretty beat. Should add a catch for null, but this should get you in the right direction. Just use the values I put in under cust1,2, and 3 to search.

    Add these to the form:

    Then add Customers as your DataSource in properties for the DataGridView

You must be logged in to reply to this topic.