Typed dataset select


I have typed dataset. Created this with XSD in VS 2010, called ProductionData.  Note the data is not from a database, it is a strongly typed.  

To bind it to a gridview on form I do this:

   Dim ds = Me.ProductionData
   DataGridView1.DataSource = ds

This binds all the fields. I'd like to bind only some e.g. Field1, Field2, Field3

Is there a "Select" statement one can do to only select a few fields?

Thanks in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you are not using  template columns in the GridView and AutoGenerateColumns is set to true, The gridview will display all the column of the dataset. If you want to display only specific columns, you can hide the unwanted columns  using the following statement

GridView.Columns[3].Visible = false;

If you are  using bound and template columns in GridView and AutoGenerateColumns is set to false, the GridView will display only those bound columns though the DataSet has many columns.
rwallacejAuthor Commented:

I'd like to keep the Gridview AutoGenerateColumns at True, and do a SELECT statement on the dataset (I presume there is a way to do this?)

I was specifying a solution for GridView which is specific to asp.net. But GridView and DataGridView
have AutoGenerateColumns  property which behaves in the same manner in the above controls. Also both have template columns.  So you can hide unwanted columns in DataGridView as below

DataGridView1.Columns[3].Visible = false;

Alternatively you can filter the columns of a datatable in the following way specied in the code snippet.

Here the DataTable dtNew  will have only records for columns CompanyName and Location. You can try to create a datable from the base datatable and bind it to DataGrid
DataTable dtComp = new DataTable();
        dtComp.Columns.Add("CompanyName", System.Type.GetType("System.String"));
        dtComp.Columns.Add("Ticker", System.Type.GetType("System.String"));
        dtComp.Columns.Add("Location", System.Type.GetType("System.String"));

        dtComp.Rows.Add(new object[] { "Microsoft", "Msft","Location1" });
        dtComp.Rows.Add(new object[] { "Intel", "Intc", "Location2" });
        dtComp.Rows.Add(new object[] { "Dell", "Dell", "Location3" });
        DataView dv = new DataView(dtComp);
        DataTable dtNew = dv.ToTable(false, new string[] { "CompanyName", "Location" });    

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

rwallacejAuthor Commented:
thanks for more info

I see there is a .Select function on the custom dataset

Me.ProductionData.Select (.......)

can this be used to select only particular columns, and so not have to recreate table?

The Select method can be used to filter rows not columns. It wil return array of DataRows based on the condition given.

The DataSet/DataTable does not have a built-in feature to filter columns.
rwallacejAuthor Commented:
thank-you for help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.