Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So, I am able to do close to what in the program, The problem I am having is when I go to select a new row, it adds the images along with the old one. If I add a Me.panel1.controls.clear statement it removes the picture, but it leaves empty spaces. I am trying to show only the pictures related to the row I pick.

Here is the code I am working with:

Private Sub Gridview_selectedIndexchenge(ByVal sender As Object, ByVal e As EventArgs) Handles DataGridView1.MouseClick

        For Each DGRS As DataGridViewRow In DataGridView1.SelectedRows

            Dim I As Integer = 0
            I = DataGridView1.SelectedRows(0).Index

            Dim IC As Integer = 0
            IC = DataGridView1.Columns(0).Index

            If DGRS.Selected = True Then

                Dim rowpic = (DataGridView1.Rows(I).Cells(0).Value)

                PictureBox1.Image = rowpic
                PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
                DGRS.Dispose()

            End If
        Next

        For Each Imgdgvi As DataGridViewImageCell In DataGridView1.SelectedCells

            Dim pic As New PictureBox()
            pic.Image = Imgdgvi.Value
            pic.SizeMode = PictureBoxSizeMode.StretchImage

            pic.SetBounds(wid, 20, 200, 100)
            ' pic.Location = New Point(10, pic.Height)
            AddHandler pic.Click, AddressOf convertPic
            Me.Panel1.Controls.Add(pic)
            wid += 205
        Next



    End Sub


Could someone help me with a simple way to remove the old and add te new through a row select?

What I have tried:

I have tried to set a for each img as picturebox in panel1.control then using a remove statement, that didn't work. I have tried the obvious me.panel1.controls.clear, but it leaves empty spaces.
Posted
Updated 5-May-17 22:21pm

1 solution

Try this

VB
Private Sub Gridview_selectedIndexchenge(ByVal sender As Object, ByVal e As EventArgs) Handles DataGridView1.MouseClick
        me.panel1.controls.clear()
        wid = 0 
        For Each DGRS As DataGridViewRow In DataGridView1.SelectedRows
 
            Dim I As Integer = 0
            I = DataGridView1.SelectedRows(0).Index
 
            Dim IC As Integer = 0
            IC = DataGridView1.Columns(0).Index
 
            If DGRS.Selected = True Then
 
                Dim rowpic = (DataGridView1.Rows(I).Cells(0).Value)
 
                PictureBox1.Image = rowpic
                PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
                DGRS.Dispose()
 
            End If
        Next
 
        For Each Imgdgvi As DataGridViewImageCell In DataGridView1.SelectedCells
 
            Dim pic As New PictureBox()
            pic.Image = Imgdgvi.Value
            pic.SizeMode = PictureBoxSizeMode.StretchImage
 
            pic.SetBounds(wid, 20, 200, 100)
            ' pic.Location = New Point(10, pic.Height)
            AddHandler pic.Click, AddressOf convertPic
            Me.Panel1.Controls.Add(pic)
            wid += 205
        Next
 

 
    End Sub
 
Share this answer
 
Comments
Member 11856456 6-May-17 13:19pm    
Thank you, works like a charm!
kosmas kafataridis 8-May-17 1:20am    
np

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900