views:

67

answers:

1

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.

A: 

I do not exaclly see your problem. YOu can make a generic IList that supports an arary of ILists as constructor and basically exposes them merged. This runs down to a lot of plumbing code, but is very generic. THe IList only needs to track which original list every item is related to, so it can properly forward delete operations.

TomTom
Im sorry but I don't really understand what you are suggesting. Could you update the answer with a snippet of code to explain?
Patrik Björklund
Sadly not. I have code for doing exactly that here, but it is about 10 pages long ;) Not complicated, though. it is called "BindingListView" and allows combining x lists input as well as filtering of exposed elements.
TomTom