troubleshooting Question

datagridview datasource doesnt sort columns

Avatar of si2030
si2030 asked on
.NET ProgrammingVisual Basic.NET
3 Comments1 Solution1037 ViewsLast Modified:
Hi Experts,

I have a datagridview that is loaded from a list obtained from a LINQ query in another sub.

I split the orginal list into 5 lists - "Assets" " Liabilities" Equity" "Revenue" Expenses".

Each of these are added to a datasource.

When running and I click on a column header it does not automatically sort. The code is below.

QUESTION:
How do I make this sort while still adding the data by datasource? Do I have to add a handle... if so how - there are two columns both need to be sorted....

Simon
Public Sub displayAccountsInDGV(ByVal accountsFound As List(Of account))
 
        'Set up the bindingsources.
        Dim assetsBS As New BindingSource()
        Dim liabilitiesBS As New BindingSource()
        Dim equitiesBS As New BindingSource()
        Dim revenuesBS As New BindingSource()
        Dim expensesBS As New BindingSource()
 
         'First lets split the filtered list of accounts into their 5 sections.
        Dim assets = From accounts In accountsFound _
                     Where accounts.acc_type = "A" _
                     Order By accounts.print_pos _
                     Select accounts.acc_id, _
                            accounts.print_pos, _
                            accounts.acc_type, _
                            accounts.acc_name, _
                            accounts.is_bank_acc, _
                            accounts.inactive, _
                            accounts.activity
 
        Dim liabilities = From accounts In accountsFound _
                          Where accounts.acc_type = "L" _
                          Order By accounts.print_pos _
                          Select accounts.acc_id, _
                                 accounts.print_pos, _
                                 accounts.acc_type, _
                                 accounts.acc_name, _
                                 accounts.is_bank_acc, _
                                 accounts.inactive, _
                                 accounts.activity
 
        Dim equities = From accounts In accountsFound _
                       Where accounts.acc_type = "O" _
                       Order By accounts.print_pos _
                       Select accounts.acc_id, _
                              accounts.print_pos, _
                              accounts.acc_type, _
                              accounts.acc_name, _
                              accounts.is_bank_acc, _
                              accounts.inactive, _
                              accounts.activity
 
        Dim revenues = From accounts In accountsFound _
                       Where accounts.acc_type = "R" _
                       Order By accounts.print_pos _
                       Select accounts.acc_id, _
                              accounts.print_pos, _
                              accounts.acc_type, _
                              accounts.acc_name, _
                              accounts.is_bank_acc, _
                              accounts.inactive, _
                              accounts.activity
 
        Dim expenses = From accounts In accountsFound _
                       Where accounts.acc_type = "E" _
                       Order By accounts.print_pos _
                       Select accounts.acc_id, _
                              accounts.print_pos, _
                              accounts.acc_type, _
                              accounts.acc_name, _
                              accounts.is_bank_acc, _
                              accounts.inactive, _
                              accounts.activity
 
        'ADD TO BINDING SOURCE AND THEN DATASOURCE..
        assetsBS.DataSource = assets
        dgvAssets.DataSource = assetsBS
 
        liabilitiesBS.DataSource = liabilities
        dgvLiabilities.DataSource = liabilitiesBS
 
        equitiesBS.DataSource = equities
        dgvEquity.DataSource = equitiesBS
 
        revenuesBS.DataSource = revenues
        dgvRevenue.DataSource = revenuesBS
 
        expensesBS.DataSource = expenses
        dgvExpenses.DataSource = expensesBS
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros