Outline ·
[ Standard ] ·
Linear+
.NET Comparing 2 datagridview, vb.net
|
TSangel-girl
|
Feb 21 2011, 02:09 PM, updated 15y ago
|
|
hi guys,the scenario is as below..
datagridview1 A B C
datagridview2 A B C D
both from different database,i wan to compare these two columns and show the one item which is not duplicate(D) in a textbox.. i'd been tryin to do tis with loop the 1st datagridview and then use the value to check one by one with the datagridview 2... but it seems more complicated,are there any solutions or methods?thank you!
|
|
|
|
|
|
la_Feng
|
Feb 21 2011, 02:13 PM
|
Getting Started

|
there is build in method from datagridview or dataset to check for that.
|
|
|
|
|
|
TSangel-girl
|
Feb 21 2011, 02:20 PM
|
|
QUOTE(la_Feng @ Feb 21 2011, 02:13 PM) there is build in method from datagridview or dataset to check for that. tq for ur reply,wat do u mean build in method?
|
|
|
|
|
|
la_Feng
|
Feb 21 2011, 02:35 PM
|
Getting Started

|
like when you do "." there are intellisense where list of existing objects will be shown. for example DataGridView1.Columns(0)....
|
|
|
|
|
|
silvestrelsl
|
Feb 21 2011, 04:10 PM
|
Getting Started

|
It is not really complicated to compare 2 data grid view with same row position. I believe you have access to both dataset. The code is simple as below: CODE DataSet ds = datagridview1.DataSource; DataSet ds2 = datagridview2.DataSource; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { for (int j = 0; j < ds.Tables[0].Columns.Count; j++) { if (ds.Tables[0].Rows[i][j].ToString() == ds2.Tables[0].Rows[i][j].ToString()) return true; } }
Be warn, need some more tweaking if you have a lot of records in the dataset.
|
|
|
|
|
|
TSangel-girl
|
Feb 24 2011, 11:45 AM
|
|
QUOTE(silvestrelsl @ Feb 21 2011, 04:10 PM) It is not really complicated to compare 2 data grid view with same row position. I believe you have access to both dataset. The code is simple as below: CODE DataSet ds = datagridview1.DataSource; DataSet ds2 = datagridview2.DataSource; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { for (int j = 0; j < ds.Tables[0].Columns.Count; j++) { if (ds.Tables[0].Rows[i][j].ToString() == ds2.Tables[0].Rows[i][j].ToString()) return true; } }
Be warn, need some more tweaking if you have a lot of records in the dataset. thx for ur reply!
|
|
|
|
|
|
ISawYou
|
Feb 13 2012, 05:28 PM
|
|
QUOTE(silvestrelsl @ Feb 21 2011, 04:10 PM) It is not really complicated to compare 2 data grid view with same row position. I believe you have access to both dataset. The code is simple as below: CODE DataSet ds = datagridview1.DataSource; [COLOR=red]<<<<This part[/COLOR] DataSet ds2 = datagridview2.DataSource; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { for (int j = 0; j < ds.Tables[0].Columns.Count; j++) { if (ds.Tables[0].Rows[i][j].ToString() == ds2.Tables[0].Rows[i][j].ToString()) return true; } }
Be warn, need some more tweaking if you have a lot of records in the dataset. I'm sorry that I'm so weak I can't do it. Needed thorough guide pls, in VB2010. How to do the above part ? assuming my values were inserted directly into DGV without using datatsources..
|
|
|
|
|