Two DataGrids, same DataSource

E

elziko

I have to DataGrids each sharing the same DataSource. The user wants to be
able to select a different row in each grid but since they share the same
source when a row is selected in one grid the same row gets selected in the
other grid.

I'd rather not have two seperate sources containing the same data since
there is often many thousands of rows.

Is there any way around this?
 
W

William Ryan eMVP

Create a dataview for each one, even if it's the same table... then bind
each grid to the different dataview.
 
E

elziko

I never did this, however did you try it with a copy of your dataset
dim mynewdataset = myolddataset.copy

As I said I'd rather not have two seperate sources containing the same data
since
there is often many thousands of rows because this would be a waste of
memory.
 
E

elziko

Thanks!
Create a dataview for each one, even if it's the same table... then bind
each grid to the different dataview.

I have tried creating two view each based onthe same table. This works but
now when I select a row in the second grid, for example, the same row gets
selected in the first grid. So its really the same problem as before.

Any idea how to stop this?
 
C

Cor Ligthert

Hi,

I saw the answer from Bill and than I knew it again, however why to answer
that again.

Cor
 
W

William Ryan eMVP

There are two different views and the grids are both bound to seperate ones?
 
W

William Ryan eMVP

I realize you mean the pointer when you say selected, not the entire row in
the grid being selected like when you click on it. Since it's a reference
type, I don't think you can do it without making a seperate copy.
 
W

William Ryan eMVP

Like I mentioned in my last post, you'll probably need to make a second
copy. However, you can use one adapter to fill each datatable, and use the
same adapter to update the datatables. I don't know the whole scenario, but
you could make this work fairly easily.
 
E

elziko

Yes I have it running OK but since I have two data tables its double the
memory and on computers with only a little RAM it runs very slowly. I'll
just have to live with it or change it so only one grid is visible at a time
(then I'll just need one drid & one data table).
 
E

Eric Matz

This should solve your problem:

DataGrid1.DataSource = MyDataSet
DataGrid1.DataMember = "Table"

'second grid needs its own BindingContext
DataGrid2.BindingContext = New BindingContext
DataGrid2.DataSource = MyDataSet
DataGrid2.DataMember = "Table"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top