Sort a datasource table by a column

Viewed 32

I have this piece of code where I am creating Labels dynamically, depending on my Features table. Now I want to order the creating by SortIndex(a column of my table features). How can I do that? I tried introducing

BindingSource bs = new BindingSource(this.productsDataSet, "Features");
bs.Sort = "SortIndex";

but it's not working. Thank you!

 this.featuresTableAdapter.Fill(this.productsDataSet.Features, this.subfamilyId);
 this.featureValuesTableAdapter.ClearBeforeFill = true;  
 this.featureValuesTableAdapter.Fill(productsDataSet.FeatureValues, subfamilyId);

BindingSource bs = new BindingSource(this.productsDataSet, "Features");
bs.Sort = "SortIndex";

foreach (ProductsDataSet.FeaturesRow feature in this.productsDataSet.Features.Rows)
{
    if (feature.IsVisible != false)
    {
        LabelControl label = new LabelControl();
        this.xtraScrollableControlFeatures.Controls.Add(label);
        label.Location = labelLocation;
        if (feature.IsRequired == true)
            label.Text = "*" + feature.Name;
        else
            label.Text = feature.Name;
        labelLocation.Y += 25;}
            label.Tag = feature;
0 Answers
Related