2

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.

enter image description here

1
  • Does this question have anything at all in it that's specific to Access? If not, then remove the tag. I don't see anything in it that relates to Access/Jet/ACE at all. Commented Jan 3, 2010 at 21:27

4 Answers 4

5
'declare this first:
imports system.componentmodel


'then put this code into a button or something
DGV.Sort(DGV.Columns(0), ListSortDirection.Ascending)

'DGv = datagridview

goodluck

Sign up to request clarification or add additional context in comments.

Comments

0

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 DataGridViewRows and set each row's visibility depending on the entered criteria:

For Each row As DataGridViewRow in dgv.Rows
    row.Visible = {some condition}
Next

1 Comment

you can definitely sort in a datagridview
0

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.

Comments

-1

try following code:

this.dataGridView1.Sort (this.dataGridView1.Columns["Yourcolumnname"], ListSortDirection.Ascending);

1 Comment

this is C# not VB.NET

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.