I do not have any idea on how to sort data using datagridview in vb.net. How do I do this by making use of textbox to input my query, I'm currently using oledb. Here is a picture of what I am trying to do. http://screencast.com/t/OWJmNDEwMjg Please help, our teacher doesn't really teach us.
Homework?
You cannot exactly sort data using a DataGridView
, but you can set the display order of data in a DataGridView
.
Set the SortedColumn
property of your DataGridView
object to the DataGridViewColumn
by which you want your data sorted. If you need a more complex sorting order, you might want to call the Sort
method with a custom IComparer
. Refer to the MSDN documentation for details.
Or do you actually want to filter your data by the two criteria for which there is an input line in your screenshot? In that case, I'm not exactly sure about the best solution. Probably you need to iterate through all DataGridViewRow
s and set each row's visibility depending on the entered criteria:
For Each row As DataGridViewRow in dgv.Rows
row.Visible = {some condition}
Next
Does the sort need to be dynamic? That is, does your customer need to be able to click on a header row and sort it?
If not, why not order the query coming back and then bind that object to the grid?
This would not be a good idea if the sort is dynamic because the cost of back and forth to the DB would not be worth it.