Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , ,

Sponsored Links



Deleting multiple images in a grid

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 12-12-2009
Member
 
Join Date: Jun 2009
Posts: 3,865
Deleting multiple images in a grid

I have a grid in which there are two columns ("Name" and "sel"), sel is a checkboxcolumn. The user will check in my grid the users it does not want, and after he removes with this code:
Code:
Private Sub tsbtnDelUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnDelUser.Click
    Dim j As Integer = dgvUsers.RowCount
    For i As Integer = 0 To j
        If dgvUsers.Rows(i).Cells("sel").Value = True Then
            dgvUsers.Rows.RemoveAt(i)
            i -= 1
        End If
    Next
End Sub
My problem is that when I delete a user, all the rest lose a row (hence my "i-= 1") so my variable j do more good value and once arriving at the end of my grid, it is still incrementing i and generates an error index. How do I change my variable for the stolen j?
Reply With Quote
  #2  
Old 12-12-2009
absolute55's Avatar
Member
 
Join Date: Nov 2005
Posts: 1,238
Re: Deleting multiple images in a grid

Its rather a collection of the list of rows check then you do one for each in this collection.
Code:
Dim linesAremove As New System.Collections.Generic.List(Of DataGridViewRow)
 
For Each line As DataGridViewRow In mydgv.rows
    If the cell of combobox is checked then 
        linesAremove.Add(line)
    End If
Next
 
For Each line In linesAremove 
    mydgv.Rows.Remove(line)
Next
working on things that move is not practical
Reply With Quote
  #3  
Old 12-12-2009
Member
 
Join Date: Jun 2009
Posts: 3,865
Re: Deleting multiple images in a grid

How? Instead of deleting it, I added in a collection and then I made one for each of the collection of items to remove? That sounds logical, but how do you save for a row in a collection?
Reply With Quote
  #4  
Old 12-12-2009
fellah's Avatar
Member
 
Join Date: May 2008
Posts: 690
Re: Deleting multiple images in a grid

Quote:
Originally Posted by AZUL View Post
How? Instead of deleting it, I added in a collection and then I made one for each of the collection of items to remove? That sounds logical, but how do you save for a row in a collection?
You can use eg an ArrayList.
Code:
Dim entries as new ArrayList
 
for i as integer = 0 to j 
  If dgvUsers.Rows(i).Cells("sel").Value = True Then
   entries.add(dgvUsers.Rows(i))
  End If
next
 
for each row as DataGridRow in entries
   dgvUsers.Rows.Remove(row)
next
Reply With Quote
  #5  
Old 12-12-2009
Member
 
Join Date: Jun 2009
Posts: 3,865
Re: Deleting multiple images in a grid

That is what I coded:
Code:
Dim LineRem As New System.Collections.Generic.List(Of DataGridViewRow)
For Each line As DataGridViewRow In dgvUsers.Rows
     If line.Cells("sel").Value = True Then
          Dim UserID As Integer = line.Cells("ID").Value
          If conSE.State = ConnectionState.Open Then conSE.Close()
          conSE.Open()
          cmd.CommandText = "DELETE FROM UsersLogin WHERE ID =" & UserID
          cmd.ExecuteNonQuery()
          conSE.Close()
          LineRem.Add(line)
     End If
Next
For Each line In LineRem 
     dgvUsers.Rows.Remove(line)
Next
My problem is that if there is only one check in step, mode has the value "DBNull" so it can not be erased. And it never erases the last of the list. Does anyone have an idea?
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Deleting multiple images in a grid"
Thread Thread Starter Forum Replies Last Post
Deleting images in Aperture Jensen Ackles Windows Software 6 28-05-2010 11:33 AM
How to display multiple images together in html Camdean Software Development 5 23-01-2010 08:32 PM
Accessing multiple images at an instance Bansi_WADIA Windows Software 3 01-12-2009 09:35 PM
Multiple Iso images on a dvd Gagnesh Operating Systems 3 18-08-2009 10:23 AM
Downloading multiple images from a site Zelgaro Customize Desktop 2 11-12-2008 05:53 PM


All times are GMT +5.5. The time now is 04:12 AM.