joe_pool_is Posted April 8, 2004 Posted April 8, 2004 I am having a problem with ListViews. Here are the specifics of my problem: Objective: Pop up ShowLayers dialog box to allow input of new layers into ShowLayers.lsvLayers listbox. When the ShowLayers form is closed, the values in ShowLayers.lsvLayers save to Form1.lsvLayers (the main form). Problem: When I call the ShowLayers dialog box again from Form1, I don't know the correct way to get the Form1.lsvLayers values back into my ShowLayers.lsvLayers listbox. Please help. First Attempt: Private Sub frmShowLayers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' // Load any existing layers... Me.lsvLayers = Form1.lsvLayers End Sub Problem with code above: The imported layers do not show up on ShowLayers.lsvLayers listbox, and any other layers added to the listbox do not show up either. However, ShowLayers.lsvLayers.Count is correct! Second Attempt: Private Sub frmShowLayers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' // Load any existing layers... Dim li As ListViewItem If Form1.lsvLayers.Items.Count > 0 Then For Each li In Form1.lsvLayers.Items lsvLayers.Items.Add(li) Next End If End Sub Problem with above code: Runtime gives me the Message: An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll Additional information: Cannot add or insert the item 'Layer01' in more than one place. You must first remove it from its current location or clone it. Calling the form is done via: dim objShow as New frmShow objShow.ShowDialog How would I remove the item if the form has been created from New? Quote Avoid Sears Home Improvement
Joe Mamma Posted April 9, 2004 Posted April 9, 2004 Not going to give you the answer here as you won't learn and learning is half the fun. ;) but some questions to be asked are, what are value types? what are reference types? what type is Me.lsvLayers? what methods does Me.lsvLayers have? answer these questions and you will have your answer:) Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
joe_pool_is Posted April 12, 2004 Author Posted April 12, 2004 I understand the difference between passing ByVal as opposed to ByRef. As to which Me.lsvLayers is, I would have to guess ByRef. How would I test this theory? (BTW: new to VB) I've spend a couple of days trying to figure this out on my own before replying again, but your answer has only left me more confused. If one version of my program has ByRef variables and another has ByVal variables, what prevents assigning one's values to another? Why is this in place? Quote Avoid Sears Home Improvement
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.