Search code examples
c#entity-frameworkadvanceddatagrid

AdvancedDataGridView Sort and Filter not working


I have AdvanceDataGridView "customerTransactionDGV with data source = customersTransactionsBindingSource.

I am changing the data source in SelectionChangeCommitted event of CustomerComboBox with below LINQ code.

this.customersTransactionsBindingSource.DataSource = dbContext.CustomersTransactions.Where(t => t.CustomerId.Equals(customerId)).ToList();
this.customersTransactionsTableAdapter.Fill(this.akDbDataSet.CustomersTransactions); 

after that filter and sort of datagridview does not work.

Removing the first line of code make it work but I need this line to populate datagridview with transactions of single user selected in CustomerComboBox.


Solution

  • This line of code:

    this.customersTransactionsTableAdapter.Fill(this.akDbDataSet.CustomersTransactions); 
    

    Apparently downloads all the customer transactions from the database. If it's true, don't do this

    Open your DataSet, find the CustomersTransactions TableAdapter, right click it, choose "Add Query", and put like:

    SELECT * FROM CustomersTransactions WHERE CustomerId = @custId
    

    Call it FillByCustomerId (and same for getdataby)

    Now in your code, leave the bindingsource alone, stop changing its datasource (its datasource should be set to, and remain as this.akDbDataSet.CustomersTransactions) and just call:

    this.customersTransactionsTableAdapter.FillByCustomerId(this.akDbDataSet.CustomersTransactions, customerId);