Resolved csv to multiple datagridviews

windoz

Member
Joined
Apr 7, 2022
Messages
5
Programming Experience
1-3
Hello,

Is there a way I can load a csv file into 5 datagridviews.

I will then assign a command button for each datagridview which will filter for something specific for each datagridviews.

The reason to the 5 datagridviews is that I can then create a dashboard which will refresh every so often and filter something specific for each like area, day, name, etc.

Many thanks.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,717
Location
Sydney, Australia
Programming Experience
10+
Are you talking about loading all the same data into all five grids? If so then the task is easy enough. Read the data into a single DataTable and then create one DataView for each grid. Bind a DataView to a BindingSource and bind the BindingSource to a DataGridView. You can then set the Filter and Sort properties of each BindingSource separately to view the same data in different ways in each grid. Just note that you should set the filters before binding the BindingSources to the grids. I'm not going to explain how to transfer the data from the file to the DataTable because that's something that can be done in a number of different specific ways and all are described on the web already.
 

windoz

Member
Joined
Apr 7, 2022
Messages
5
Programming Experience
1-3
Hi,

Yes, correct i want load the same data into all 5 datagrids.

I've managed to load the csv into the 5 different datagridviews, however when I apply a filter to search one of the datagridviews, it seems to filter all 5 with the same search and all 5 datagridviews show the exact same search data.

Even though I applied:

bindingsource1. Datasource = dt
Bindingsource2. Datasourcr =dt
bindingsource3. Datasource = dt
Bindingsource4. Datasource =dt
bindingsource5. Datasource = dt

Datagridview1. Datasource=bindingsource1. Datasource

Datagridview2. Datasource=bindingsource2. Datasource

Datagridview3. Datasource=bindingsource3. Datasource

Datagridview4. Datasource=bindingsource4. Datasource

Datagridview5. Datasource=bindingsource5. Datasource


What am I doing wrong?

Many thanks.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,603
Location
Norway
Programming Experience
10+
When you assign dt DataTable its DefaultView is used, so same view is used for all grids, @jmcilhinney said that you should create a new DataView for each grid: New DataView(dt) will do that.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,717
Location
Sydney, Australia
Programming Experience
10+
If you were only binding the data once then there would be no need to create DataViews explicitly, because the data would come from the DefaultView of the DataTable, which is a DataView. That view can only be filtered one way though. If you want to filter each grid differently then you need a separate view for each grid, which means that you need to do what I said to do:
Read the data into a single DataTable and then create one DataView for each grid. Bind a DataView to a BindingSource and bind the BindingSource to a DataGridView.
If you don't do as instructed, it's not likely to work as intended. I also said:
You can then set the Filter and Sort properties of each BindingSource separately to view the same data in different ways in each grid. Just note that you should set the filters before binding the BindingSources to the grids.
but I don't see that anywhere either.

By the way, if you do this:
VB.NET:
Datagridview1. Datasource=bindingsource1. Datasource
then the BindingSource is pointless. I said bind the BindingSource, not its DataSource:
VB.NET:
DataGridView1.DataSource = BindingSource1
 
Top Bottom