Two DataGrids, same DataSource

  • Thread starter Thread starter elziko
  • Start date Start date
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?
 
Create a dataview for each one, even if it's the same table... then bind
each grid to the different dataview.
 
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.
 
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?
 
Hi,

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

Cor
 
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.
 
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.
 
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).
 
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"
 
Back
Top