Sorting of Data grid view which is bound table


Sorting of Data grid view which is bound table



I want my first column sort of data grid view when form load. but i have no code. Below i attach my loding code.


Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'EmployeeTBDataSet.Table1' table. You can move, or remove it, as needed.
Me.Table1TableAdapter.Fill(Me.EmployeeTBDataSet.Table1)
End Sub




1 Answer
1



You have presumably dragged a table from the Data Sources window onto your form to create that DataGridView and the code that populates the DataTable it is bound to. That will also have created a BindingSource and that is where you perform most actions related to the bound data, including sorting. After that call to Fill, set the Sort property of that BindingSource to the name of the column you want to sort by, e.g.


DataGridView


DataTable


BindingSource


Fill


Sort


BindingSource


Me.Table1BindingSource.Sort = "Table1ID"



That will sort in ascending order implicitly. You can also sort in ascending or descending order explicitly, e.g.


Me.Table1BindingSource.Sort = "Table1ID DESC"





Thanks. it works
– rkdev
Jul 2 at 11:40






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Rothschild family

Cinema of Italy