Merging ILists to bind on datagridview to avoid using a database view

Posted by P.Bjorklund on Stack Overflow See other posts from Stack Overflow or by P.Bjorklund
Published on 2010-05-03T08:57:28Z Indexed on 2010/05/03 9:08 UTC
Read the original article Hit count: 173

Filed under:
|
|

In the form we have this where IntaktsBudgetsType is a poorly named enum that only specifies wether to populate the datagridview after customer or product (You do the budgeting either after product or customer)

private void UpdateGridView() {

    bs = new BindingSource();
    bs.DataSource = intaktsbudget.GetDataSource(this.comboBoxKundID.Text, IntaktsBudgetsType.PerKund);

    dataGridViewIntaktPerKund.DataSource = bs;
}

This populates the datagridview with a database view that merge the product, budget and customer tables.

The logic has the following method to get the correct set of IList from the repository which only does GetTable<T>.ToList<T>

public IEnumerable<IntaktsBudgetView> GetDataSource(string id, IntaktsBudgetsType type)
        {
            IList<IntaktsBudgetView> list = repository.SelectTable<IntaktsBudgetView>();

            switch (type)
            {   
                case IntaktsBudgetsType.PerKund:                            
                    return from i in list
                           where i.kundId == id
                           select i;
                case IntaktsBudgetsType.PerProdukt:                    
                    return from i in list
                           where i.produktId == id
                           select i;
            }

            return null;
        }

Now I don't want to use a database view since that is read-only and I want to be able to perform CRUD actions on the datagridview.

I could build a class that acts as a wrapper for the whole thing and bind the different table values to class properties but that doesn't seem quite right since I would have to do this for every single thing that requires "the merge".

Something pretty important (and probably basic) is missing the the thought process but after spending a weekend on google and in books I give up and turn to the SO community.

© Stack Overflow or respective owner

Related posts about c#

Related posts about datagridview