Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Experts*
Posted

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):

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:

'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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...