This is part of the last coding that codeorder helped me with. I didn't include this in the last post because I thought this was something that I was going to be able to do. Unfortunately, it is not working properly. In addition to the controls being removed, the control rows after the removed row should be changed so it's still in sequential order.
Private Sub PictureBoxRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim RowRemove As String = CType(sender, PictureBox).Name.Replace("PictureBoxRemove", "")
PanelArea.Controls.Remove(CType(PanelArea.Controls("PictureBoxAdd" + RowRemove.ToString), PictureBox))
PanelArea.Controls.Remove(CType(PanelArea.Controls("PictureBoxRemove" + RowRemove.ToString), PictureBox))
PanelArea.Controls.Remove(CType(PanelArea.Controls("TextBox" + RowRemove.ToString), TextBox))
PanelArea.Controls.Remove(CType(PanelArea.Controls("Button" + RowRemove.ToString), Button))
Dim RowBefore As Integer = CInt(SegmentRemove) + 1
Dim RowAfter As Integer = CInt(SegmentRemove)
While RowBefore <= RowTotal
' Replace all controls names below to replace the removed control.
PanelArea.Controls("PictureBoxAdd" + RowBefore.ToString).Name.Replace("PictureBoxAdd" + RowBefore.ToString, "PictureBoxAdd" + RowAfter.ToString)
PanelArea.Controls("PictureBoxRemove" + RowBefore.ToString).Name.Replace("PictureBoxRemove" + RowBefore.ToString, "PictureBoxRemove" + RowAfter.ToString)
PanelArea.Controls("TextBox" + RowBefore.ToString).Name.Replace("TextBox" + RowBefore.ToString, "TextBox" + RowAfter.ToString)
PanelArea.Controls("Button" + RowBefore.ToString).Name.Replace("Button" + RowBefore.ToString, "Button" + RowAfter.ToString)
' Move up all controls below removed control to takes its place.
PanelArea.Controls("PictureBoxAdd" + SegmentAfter.ToString).Top -= 30
PanelArea.Controls("PictureBoxRemove" + SegmentAfter.ToString).Top -= 30
PanelArea.Controls("TextBox" + SegmentAfter.ToString).Top -= 30
PanelArea.Controls("Button" + SegmentAfter.ToString).Top -= 30
RowBefore += 1
RowAfter += 1
End While
RowTotal -= 1
End Sub
Before this code, "PanelArea.Controls("PictureBoxAdd" + RowBefore.ToString).Name.Replace("PictureBoxAdd" + RowBefore.ToString, "PictureBoxAdd" + RowAfter.ToString)" I used the same coding in a MsgBox() so I can determine what the new PictureBoxAdd name was going to be and it showed the correct value but I'm getting some error that's related to the object is not being referenced. I hope this is clear enough to understand what I wanted to do. Thanks.