views:

269

answers:

2

I create a custom dataset that I pass off to a black boxed component. The dataset consists of usually 5-6 tables (with unique names assigned by me). The component takes the dataset and builds a drop down combo box based off the table names. What I am needing to do though is to change the ordering of the tables within the dataset. I need to do this so I first offer up to the user the appropriate selection in the drop down (based off what section in the application they are in). So for instance...if they are in "Section A" then that is the first table name shown in the drop down list...if the user goes to "Section F" then that is what is shown in the list first...so on and so forth.

The more code intensive way is of course to just change the ordering in which I add the tables to the dataset. This would work, but I thought there had to be some way to do this more elegantly and with less code.

I am working in C# with the 3.5 framework.

+2  A: 

Remember that DataSets and their contents are stored on the heap, so you can have a DataTable object in more than one place in the DataSet.

Simply create your DataSet with a dummy DataTable in position zero. Then, based on whatever section they'e in, you put the corresponding table in position zero. Your table name will appear twice in your DropDownBox, once as the 'default' and again below in its proper context and order with the other tables.

public class ThisThing
{
    private DataSet myDS = new DataSet();

    //Populate your DataSet as normal

    public DataSet ChangeLocation(int CurrentSectionNumber)
    {    
        myDS.Table[0] = myDS.Table[CurrentSectionNumber]
    }
}
Rap
A: 

I'm not sure trying to force your ordering information into the DataSet's data structure is the most intuitive approach. You might consider passing an ordered list of DataTable instead of (or in addition to) the DataSet.

Ken Browning