Hi gang,

I have a unique challenge that I just cannot seem to get by...I have a form with a series of listboxes that allows the user to rename items in the listbox (I probably should be using a listview control instead). When the user right-clicks and selects rename from the context menu I show a simple form with two labels & text boxes showing the selected list box item in one textbox...the other is blank waiting for the user to enter a new name. What I'd like to do is when the user closes the rename form, the information is passed back to the calling form and a listbox refresh method is fired to show the changed name. Couple question:

First, is there an easier method to implement the renaming concept in a listbox (probably should be using a list view) i.e., have I overcomplicated things?

Second, does anyone have any suggestions or code examples to share that would shed some light on my challenge.

Any thoughts/suggestions would be greatly appreciated.

cheers

Recommended Answers

All 4 Replies

Whenever I need to pass info between dialogs, I make public properties on the 2nd dialog. For example, if I had a dialog with a textbox that I preset the text, then let the user change, I would add this to my 2nd dialog (assuming the textbox ID was "myTextBox")

Public Property Usertext() As String
        Get
            Return myTextBox.Text
        End Get
        Set(ByVal Value As String)
            myTextBox.Text = Value
        End Set
    End Property

Then, when I want to use this:

Dim myDialog as New MyDialog()
myDialog.UserText = "change me!"
If myDialog.Show() = DialogResult.OK
Print("You entered: " & myDialog.UserText)
End If

(warning: i typed all this from memory, and didn't try compiling it for errors, but I hope my point is made. Also, I may be doing it wrong in general, but this usually works for me.)

Thanks mikiurban...that was the line of thinking for getting information from one form to the other and that worked, but I'm still trying to figure out how to fire an event on one form when another is closed down.

Here's the sequence of events generalized: in form1 I create a second form2 and let the user rename a list box item. What I am trying to do is fire a refresh listboxes event when form2 closes and set the focus back to the listbox (selecteditem) on form1. My logic may be flawed as I'm sure there is a better way to let the user rename an item in a listbox so any suggestions would be greatly appreciated.

cheers,

Whenever I need to pass info between dialogs, I make public properties on the 2nd dialog. For example, if I had a dialog with a textbox that I preset the text, then let the user change, I would add this to my 2nd dialog (assuming the textbox ID was "myTextBox")

Public Property Usertext() As String
        Get
            Return myTextBox.Text
        End Get
        Set(ByVal Value As String)
            myTextBox.Text = Value
        End Set
    End Property

Then, when I want to use this:

Dim myDialog as New MyDialog()
myDialog.UserText = "change me!"
If myDialog.Show() = DialogResult.OK
Print("You entered: " & myDialog.UserText)
End If

(warning: i typed all this from memory, and didn't try compiling it for errors, but I hope my point is made. Also, I may be doing it wrong in general, but this usually works for me.)

I think I'm spending too much time at the keyboard, but I've figured out the answer to my question...use the form.paint event to fire the refresh listbox method.

Thanks again mikiurban...you got me on the right track to solving the problem.

cheers

Thanks mikiurban...that was the line of thinking for getting information from one form to the other and that worked, but I'm still trying to figure out how to fire an event on one form when another is closed down.

Here's the sequence of events generalized: in form1 I create a second form2 and let the user rename a list box item. What I am trying to do is fire a refresh listboxes event when form2 closes and set the focus back to the listbox (selecteditem) on form1. My logic may be flawed as I'm sure there is a better way to let the user rename an item in a listbox so any suggestions would be greatly appreciated.

cheers,

I know this is flagged solved, but if you really want a form closing to call a function in another form, you should create an Event object with a delegate (which is a function to do something) in your main form, and pass that event to the child form. In the child form's Form_Closing() function, call RaiseEvent() which will eventually process the delegate. There are a lot of hoops, and I've never done it in vb.net (I did in C# and C++, but it was a while ago, which doesn't help much.)

There are a lot of places events like this are useful, but just getting two forms to talk to each other, I usually use the the code I already provided :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.