Datagridview - Sort column through a button

Asked

Viewed 460 times

1

I wonder if there is any way to sort a column, from a datagridview, by clicking a button on the form after Datagridview is already populated.

1 answer

0


It is possible to make a Sort the columns after doing the Binding in this way:

DataGridView1.Sort(DataGridView1.Columns("Name"), System.ComponentModel.ListSortDirection.Ascending)

Anyway it is recommended, if the information in the grid comes from a query SQL, sort the logs before popular the grid.

  • Good morning, the grid information comes from an sql query. I implanted the example you gave me and it worked seemingly smoothly in ordering the proposed column after popular datagridview. If possible, watch me for the problems I might have.

  • The example I indicated works, but I mentioned the question of ordering directly in the SQL query for a question of performance, because sorting the information that is already in the grid can take much longer than in the SQL query itself. Of course this becomes more visible with large amounts of information.

  • Thanks João Martins. I am new here, please inform me how I can give the topic as closed and pass to the site the help that provided me. A hug

  • If the answer helped you, then please confirm it as correct (a grey visa below my answer, if I am not mistaken) and vote yes on the answer (if you have the reputation to do so). Thank you! You are hereby informed how to accept a reply: https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work

Browser other questions tagged

You are not signed in. Login or sign up in order to post.