Link to home
Start Free TrialLog in
Avatar of si2030
si2030

asked on

datagridview datasource doesnt sort columns

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of rionroc
rionroc
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of si2030
si2030

ASKER

Hi Rionroc,

The object you are suggesting would this be the DGV?  I had the idea this issue was because the datasource being appled was a list and needed to be someother type. I have five DGVs on the form and they all dont sort.

Simon
Avatar of si2030

ASKER

Appreciated you're help.

SImon