inter-form communication

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

VB.Net >>
Can someone give me some insights as to communicating info between
2 forms. Generically, I have the following - 1 form with a datagrid which is
the result of a search operation. Another form that holds detailed data for
each row in the search result grid.

I would like the ability to double-click on a row in the searchresult form
and have all the data populate in the main form. I have written all the code
to do the population on the main form, I just need a way to 'fire' the event
in the main form from the search grid form. Any suggestions / links, etc.
Thanks in advance
 
The method I use to do this is to pass a reference of one form to the other.
public class Form2
dim OtherForm as Form
sub new(byref Value as Form) 'Send in Form1
otherform = Value
end sub
end class

Then create some properties in Form1 to return the information you need in
form2.

'Very crude way of doing it
Public Class From1
public readonly property DG() as datagrid
.... Return DataGrid
end property
end Class

No code was ran in the IDE, all typed here so beware....
Hope it sparks some ideas.
Chris
 
Would it be true to say that the main form creates the form with the grid?
If so, it has a handle/reference to the sub-form. I would have an event in
the sub-form that is fired when the user double-clicks, and create a class
derived from EventArgs to pass the data to display.

Before the main form displays the sub-form, add a handler to sink the
sub-form event. Then, when the event fires, the main form can do the
populating thing.

HTH

Charles
 
Back
Top