search result in a popup window

wdw

Freshman
Joined
Dec 11, 2002
Messages
37
Hello,

I have the following problem:

I want to have a popup box that displays the results of a search in a datagrid. After displaying the results the user can select a row and then the form must be filled with that specified record. I know how to make a search method that displays data in a datagrid, but i don't know how to make it in a popup and i have no idea how to throw the information back to the form.

can someone help me with this problem.
I'm programming in vb.net (windowsforms application)

thanks very much

Willem
 
To get the popup window, you'll want the ShowDialog method of the form. To get values back, simply expose what you want as a public field on your popup form.

For example, assume you have Form1 (the main window) and Form2, the popup. Also assume you want to expose the selected row as a DataRow on Form2, so that Form1 can display the data that was selected.
Here's what Form1 might look like (maybe this is in a button click event or somesuch):
Visual Basic:
Dim f2 As Form2 = New Form2()
f2.ShowDialog()
'The following line will execute once Form2 has been closed
If Not f2.SelectedRow Is Nothing Then
    'They selected something, assign it to a local variable, dr
    'dr would likely be stored at the form level, as a private DataRow variable
    dr = f2.SelectedRow
End If

The following chunk is in Form2:
Visual Basic:
'At the top of the form:
Public SelectedRow As DataRow

'In the Double-Click event or a Select button's click event
Me.SelectedRow = ... 'Select the Row from the grid and assign it here
Me.Close()

'In the Close or Cancel button, if you have one:
Me.Close() ' Nothing special, SelectedRow will default to Nothing

-Nerseus
 
Back
Top