Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

.NET Comparing 2 datagridview, vb.net

views
     
TSangel-girl
post Feb 21 2011, 02:09 PM, updated 15y ago

Look at all my stars!!
*******
Senior Member
3,408 posts

Joined: Nov 2008
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
post Feb 21 2011, 02:13 PM

Getting Started
**
Junior Member
170 posts

Joined: Jul 2009
there is build in method from datagridview or dataset to check for that.

TSangel-girl
post Feb 21 2011, 02:20 PM

Look at all my stars!!
*******
Senior Member
3,408 posts

Joined: Nov 2008
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
post Feb 21 2011, 02:35 PM

Getting Started
**
Junior Member
170 posts

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

Getting Started
**
Junior Member
222 posts

Joined: Aug 2009
From: Cyberjaya


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
post Feb 24 2011, 11:45 AM

Look at all my stars!!
*******
Senior Member
3,408 posts

Joined: Nov 2008
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
post Feb 13 2012, 05:28 PM

On my way
****
Senior Member
531 posts

Joined: Oct 2011
From: Tawau -> Menumbok, Sabah(Land Below The Wind)



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..

 

Change to:
| Lo-Fi Version
0.0192sec    0.61    5 queries    GZIP Disabled
Time is now: 13th December 2025 - 12:48 PM