I have 3 DataGridViews in a form in C#. I configured one datagridview than copy+paste the other two. They got the same datatable as datasource. The problem is that when I click on a cell in any datagridview the selected row is changing in the other two. How can I delete this beahviour?
Asked
Active
Viewed 54 times
0
-
1copy the data source 3 times. if it is `DataTable`, then use `Copy` method. – Lei Yang Jul 26 '17 at 07:11
-
Change the eventhandler method name for all the DataGridViews. All should be with different names. – Abhishek K. Upadhyay Jul 26 '17 at 07:12
-
You should set datasource of each datagridview to different datatable. If dt is a datatable that every gridview is using then you can create new datatable by dt1 = dt.Copy() then assign dt1 as datasource to other gridview – Bhuban Shrestha Jul 26 '17 at 07:12
-
With something like Datatable dt1=dt it did not worked, but it worked with copy(). Thanks – Ciobotaru Costel Jul 26 '17 at 07:14
-
`dt1=dt` will only copy the reference. Both objects will still refer to the same entity in memory. This is why changing the one has changed the other – Mong Zhu Jul 26 '17 at 07:17
-
You should indirect the datasource by inserting bindingsources, which are based on the datatable! – TaW Jul 26 '17 at 08:16
-
@MongZhu but why it affected only the row and the column was not affected? – Ciobotaru Costel Jul 26 '17 at 11:43