Multiple datagridviews same form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using VB within VS 2005. How can I have multiple datagridviews on the
same form pulling from the same table? e.g. I want to see all clients from
New York in one view and all clients from LA in another view on the same
form. I've set up a parameterized tableadapter and pass it the city. How can
I load the two views in VB code when the form loads?

Thanks,

Tom
 
Hi Tom,

Pull all of your data into a dataset and then just create two dataviews from
your dataset. Then assign each dataview to a separate grid.

ex:

.....code to load dataset

Dim dv1 As DataView = New DataView(ds.Table ("MyTableName"), "city=NY", "",
DataViewRowState.CurrentRows)

Dim dv2 As DataView = New DataView(ds.Table ("MyTableName"), "city=LA", "",
DataViewRowState.CurrentRows)
 
....or (thinking more in terms of performance) just call your table adapter
query twice - once for LA and once for NY - assigning the results to a
different dataset (i.e. create two datasets in your client application). Then
assign each dataset to a different grid.

You can essentially have as many datasets as you want in your app:

ex:

Dim ds as new system.data.dataset
Dim ds2 as new system.data.dataset
Dim ds3 as new system.data.dataset

....and just fill each one of them up with different calls to your table
adapter.
 
Thanks for the responses. Creating multiple datasets works. However, I would
prefer to create my datasets and dataviews on the form at design time, rather
than create them on the fly at runtime. It also appears multiple datasets
will require me to create duplicate queries (in seperate tableadapters),
resulting in more difficult maintenance if the query changes.

Thanks again,

Tom
 
Back
Top