473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Datagridview

OuTCasT
374 256MB
I have 2 datagridviews on my form.
DGview1 gets its rows from a .xls form
and
DGview2 gets its rows from the SQL database

Now i need to loop through DGview1 and remove the rows that are equal to the rows that are in DGview2

Expand|Select|Wrap|Line Numbers
  1. dim row as datagridviewrow
  2. for each row in datagridview1.rows
  3. next
could anyone help me out ?
Jul 16 '09 #1
3 1934
smartchap
236 100+
I have not worked much on Datagridviews. But first of all read all the filled rows in DGview1 and store it as, say, RDGView1. then read filled rows in DGview2 and store it in, say, RDGView2. Now use two For loops, first for RDGView1 & inner one for DGView2. After first loop statement store all column data in a variable like DDGView1 for each row one by one and in inner loop save data of all columns for row in , say, DDGView2. It may be like this

Expand|Select|Wrap|Line Numbers
  1. RDGView1=No. of filled rows in DGView1
  2. RDGView2=No. of filled rows in DGView2
  3. For i = 1 to RDGView1
  4.      DDGView1=data of first col of row i + data of second col of i row + ...+data of last col of row i (of DGView1)
  5.      For j = 1 TO RDGView2
  6.          DDGView2=data of first col of row i + data of second col of i row + ...+data of last col of row i (of DGView2)
  7.          IF DDGView2=DDGView1 then
  8.             here delete row j of DGView2
  9.          End If
  10.      Next
  11. Next
  12.  
I think I tried to make a logic to be used.
Jul 17 '09 #2
OuTCasT
374 256MB
Expand|Select|Wrap|Line Numbers
  1. Try
  2.             'remove all the unsubscribed entries from the upload grid
  3.             Dim val3 As String = Nothing
  4.             Dim val4 As String = Nothing
  5.  
  6.             'loop through DG1
  7.             For Each row As DataGridViewRow In DataGridview1.Rows
  8.  
  9.                 'Check datagridview 1 and get Value
  10.                 If Not (row.IsNewRow) Then val3 = DataGridview1.Rows(row.Index).Cells(0).Value.ToString
  11.  
  12.                 'Loop through DG2
  13.                 For Each row1 As DataGridViewRow In DataGridView2.Rows
  14.  
  15.                     'Check DG2 and get Value
  16.                     If Not (row1.IsNewRow) Then val4 = DataGridView2.Rows(row1.Index).Cells(0).Value.ToString
  17.  
  18.                     'Compare values and remove from DG1
  19.                     If val3 = val4 Then
  20.                         ' Remove the duplicate from the upload grid
  21.                         If Not (row1.IsNewRow) Then DataGridview1.Rows.Remove(DataGridview1.Rows(row.Index))
  22.                     End If
  23.                 Next
  24.             Next
  25.             PleaseWait.Close()
  26.         Catch ex As Exception
  27.  
  28.         End Try
If i do it this way it only loops through DG1 once and removes the correct item and then its stops looping through
Jul 17 '09 #3
smartchap
236 100+
After deleting / removing a row total no. of rows in that grid will change, i.e. will be 1 less than previous. So take care of this and after removing a row recalculate total no. of rows in that grid. I think it will help u.
Jul 18 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: DraguVaso | last post by:
Hi, I'm using the DataGridView in VB.NET 2.0. The DataSource is a Generic List of a custom class0: lstMyPersonnes = New List(Of clsPersonne). When I add a new clsPersonne to lstMyPersonnes,...
10
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. Basically, on my form I have a DataGridView, it's got...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
2
by: bob | last post by:
Can anyone tell me the best way to update a dataset while it is being edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should...
7
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
0
by: jeastman - Hotmail | last post by:
Hello world Excuse, not to be written English and it helps me with a translator. I am new programming in C#. I made a control inheriting the DataGridView to be able to add controls done by...
3
by: Andrus | last post by:
I have DataGridView in virtual mode containing 3500 rows. In code below, assigning to RowCount value to 3500 takes 8 seconds. CPU usage goes high at this time. Stepping by F11 into user code shows...
0
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
2
BRawn
by: BRawn | last post by:
Hi guys, I'm struggling to copy rows from one DataGridView to another. This may sound redundant but it's necessary for my Orders project. I have 3 DataGridViews on one form. The first...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.