showdialog - how to access parent form

MondeoST24

Member
Joined
Mar 9, 2006
Messages
16
Programming Experience
Beginner
Hi,

I have a form, it has two textboxes txtName, txtAddress, it also has a button, the button opens another form as a dialog

Dim select as new frmSelect
select.showdialog

On the select dialog it displays a datagrid with a list of customers, user double clicks on an entry and I trap that event, I then want to update the textboxes on the parent form with the values fromt the selected row in the grid.

How do I access the parent forms controls/properties?

Thanks
 
How about if you in frmSelect provided a public property (or two..) where you store the values selected? Then you set Me.DialogResult = DialogResult.OK. Now, in parent form you can check the return value of the ShowDialog method, if it was OK you get the values from the public properties before you dispose of the frmSelect instance.

Here is some pseudo code to get an overview:
VB.NET:
class mainform
  inherits form
 
  sub btnSelect_click(sender,e) handles btnSelect.click
    dim f as new frmSelect
    if f.ShowDialog = DialogResult.OK then
      msgbox("you selected " & f.Value)
    end if
    f.Dispose()
  end sub
end class
 
 
class frmSelect
  inherits form
 
  public Value as string
 
  sub datagrid_doubleclick(sender,e) handles datagrid.doubleclick
    value = datagrid.selectedvalue
    me.DialogResult = DialogResult.OK
  end sub
end class
Here I just used a public variable (Value), but it is better if you get used to the Property statement where you can restrict to ReadOnly, add custom behaviours and similar stuff.
 
Back
Top