Sharing a Search form

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

Guest

In an SDI application, I'd like to share a single instance of a Search form
across more than one form.

Currently, I'm creating an instance of a Search form from the form (say
Form1, Search button Click event) where I wish to do a Search. Then I'm
subscribing to an event that the Search form will raise when the user selects
a matching record. Like this:

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSearch.Click
m_thisSearch = New SearchForm
AddHandler m_thisSearch.SelectedItem, AddressOf ItemSelected
m_thisSearch.Show()
End Sub

Private Sub ItemSelected(ByVal ItemID As String)
' This procedure gets invoked when a ItemID is selected on the
Search form.
txtItemID.Text = ItemID
End Sub

If the SearchForm is implemented as a Singleton, and the event is subscribed
to by more than one form, all forms will receive the event message. I'd like
to target the result of the search to be directed only to the form from which
the SearchForm was most recently invoked. And the SearchForm may *not* be
Modal.

Any suggestions/ideas/comments are most welcome. Please help.

Thanks.
 
Hi Harry

I don't think you need to register events in this case. You can achieve your
goals using the Owner property of your SDI Form.

Imagone you have a static / Shared method on your SearchForm class called
GetForm. When you call this, you get your single instance back. Then you set
the Owner to this / Me. Now when you want to invoke a method of the current
owning form, you just get the Owner...

If you want some code, then I could show you?

HTH

Nigel Armstrong
 
Nigel,

Thanks for the suggestion.

<ThinkingOutLoud>
That might do it. Side effects would be:
1) SearchForm would always be on top of the owner form.
2) The invoking form(s) need to implement a standard method that SearchForm
can call when the user makes a selection.
</ThinkingOutLoud>

Any way of getting around point (2) above? That's why I went the "raise an
event when the user makes a selection" route in the first place.

Thanks.
 
Hi Harry

Have the MainForm(s) implement an interface or have a base form class with
an Overridable / virtual method - cast the Owner to that interface / base
class. Then the implementation is up to you...

Nigel
 
Nigel,

Thank you very much.

Looks like I have some research to do to figure out the actual
implementation. :-)

Thanks again.

Harry
 
Back
Top