On form1 I instantiate form2 with a list box. I do I handle listboxclick from form1

P

PAPutzback

Form2 has one purpose to open and list some names and ids. I want to
handle the list box click event on form2 so I can get the selected
value onto a field in form1.

I changed this
Dim MyForm2 As New PHfx.Form2
to
With Events MyForm2 As New PHfx.Form2
and tried adding an event handler but intellisense will not show form2s
objects, just the methods.

This does not pull up the intellisense
sub onlistClick(ByVal sender As System.Object, ByVal e As
System.EventArgs) handles MyForm2.XXXXXX - where is my listbox listed so
I can handle it's click event and get the selectedvalue.

Thanks,
Phil
 
C

Chris, Master of All Things Insignificant

You can pass a reference of form1 into form two at creation. Then just fill
in the property you need.

Class Form2
RefToForm1 as Form1
sub new (ByRef F as Form1)
mybase.new()
RefToForm1 = F
end sub
Sub SomethingDone()
RefToForm1.FieldToUpdate = Data
End Sub
end class

Hope it helps
Chris
 
P

PAPutzback

It isn't clear to me. When an item is selected in the listbox on form 2
I want to see the selected value from form1 and put it into a text
box.with no user intervention other than clicking the listbox on form
2.

I thought I could add a handler to form1 to handle the click event of
the listbox on form2

Or maybe I just get the syntax of the code you put up

Class Form2
RefToForm1 as Form1
sub new (ByRef F as Form1)
mybase.new()
RefToForm1 = F
end sub

Thanks,
Phil
 
C

Chris, Master of All Things Insignificant

Sorry I think I misunderstood what you wanted.

You want the user to select an item in Form2.listbox. Then get a value from
Form1.SomeControl and put it into a Form2.Textbox. The idea behind my code
will still work. You may be able do what your talking about doing, I've
just never done it.

So in this example Form2 now has a reference to Form1 called "RefToForm1"
Class Form2
RefToForm1 as Form1
sub new (ByRef F as Form1)
mybase.new()
RefToForm1 = F
end sub

Sub OnClickListBox(....) handles Listbox1......
Textbox1.Text = RefToForm1.GetSomeValueFromForm1(SomeThingPassedIn)
End Sub
End Sub

Class Form1
Sub OpenForm2
Dim F2 as New Form2(Me)
F2.ShowDialog()
End Sub

Public Function GetSomeValueFromForm1(ByVal SomeValueFromForm2 as
String) as String
return WhateverYouWantedOnForm2
end function
End Class

Obviously I wrote the code in here ad it wasn't tested. But that is the
idea. Form2 now has knowledge about Form1. Form1 now has a method that
Form2 can call and return some value to Form2.

I hope this helps
Chris
 
P

PAPutzback

I got thru this by binding the text box to the selected value of the list
box.

Me.txt_Provider.DataBindings.Add( _
New Binding("text", My_PCPlist.PCPList, "SelectedValue"))

Thanks,
Phillip
 
G

Guest

Hi

I think it is easier with ShowDialog method (if the form2 only purpouse is
to select a provider) then could do something like this:

class form1
sub getProvider
provider as string
provider=form2.showDialog
end sub
end class

class form2
sub HandlesClick (sender...) Handles list.click
Me.tag=list.selectedvalue
me.close
end sub
end class

This code is pseudoCode Too but surely works

Regards!

Omar Rojas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top