C # Reordering tables in a dataset

I am creating my own dataset which I pass to the black box component. The dataset usually consists of 5-6 tables (with unique names assigned by me). The component takes a dataset and creates a drop down combo box based on the table names. What I need to do is reorder the tables in the dataset. I need to do this, so I first present the user with the appropriate choice in the dropdown (based on the section they are in). So, for example ... if they are in Section "A", this is the first table name listed in the dropdown ... if the user navigates to Section F, then this is what appears first in the list ... etc. .d.

More code intensive is of course just changing the order in which I add tables to the dataset. It would work, but I thought there must be some way to do it more elegantly and with less code.

I am working in C # with framework 3.5.

+2


source to share


2 answers


Remember that DataSets and their contents are stored on the heap, so you can have a DataTable in multiple places in the DataSet.

Just create your DataSet with a dummy DataTable at position zero. Then, based on whatever partition they are in, you put the corresponding table at position zero. Your table name will appear twice in the DropDownBox, once "by default" and again below in the appropriate context and order with 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]
    }
}

      

+2


source


I'm not sure if trying to force your ordering information into a data structure DataSet

is the most intuitive. You can consider the passed ordered list DataTable

instead of (or in addition to) the DataSet.



0


source







All Articles