Results 1 to 9 of 9

Thread: common form ..

  1. #1

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437

    common form ..

    Let's say I have 5 different forms. All of them have a field called Sql. Where user can go and type there SQL queries. Now, since the Sql field is not big enough on all the forms (due to less screen space), I provided a context menu on this field, where user can right click and select Large, which will open a new form with only one textbox and ok, cancel buttons. Now user can go and enter there SQL query easily here.

    The question is, since this can be opened from all 5 forms, which is the best method to return the value from this SQL form, to the form which has opened the large SQL form. Remember, you can only open it for one form at a time because its opened as ShowDialog.

  2. #2
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    when you have a form open this new form, make sure the new form is owned by the form that opened it, then check the parentform property of the new form and update an Item from it.

    Need an example?
    Whadayamean it doesn't work....
    It works fine on my machine!

  3. #3

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    Originally posted by CyberHawke
    when you have a form open this new form, make sure the new form is owned by the form that opened it, then check the parentform property of the new form and update an Item from it.

    Need an example?
    Well, actuallym I did it already using Interfaces (again). ParentForm does not actually work, you have to use Owner. However, I ran into something else now. Its returning the Sql to its owner perfectly using Interface.

    The question now is, when I am clicking on context menu button Large, to open this Sql form, and if my text box on parent form already has some Sql, I would like to display it in the textbox of Sql form.

    So in parent form I did something like this ...

    VB Code:
    1. Private Sub miLarge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miLarge.Click
    2.  
    3.         Dim objectSQL As New Sql([b]txtExportSQL.Text[/b])
    4.         objectSQL.ShowDialog(Me)
    5.     End Sub

    and in sql form, in the constructor, I passed the Sql and stored in a private variable and on form load I am trying to load this private variable in the text box. But its giving error, object no set reference and all that crap.......any idea ?

    VB Code:
    1. Private m_Sql As String
    2.  
    3.     Sub New(ByVal sql As String)
    4.         m_Sql = sql
    5.     End Sub
    6.  
    7.     Private Sub Sql_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    8.         txtSql.Text = m_Sql
    9.     End Sub

  4. #4
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    If I well understood (always my bad english make me not sure), you have a problem to transfer what is contained in Form1TxtSQL to FormDialogTxtSQL.

    You have two ways:

    1) You can write from Form1 into FormDialog that value and you shouldn't have problem. Then you can read what is contained in FormDialogTxtSQL when it will close (more exactly it will have to set its DialogResult property to, for example, CANCEL). Then, when you have read the value of the 'giant textbox' you can close the modalform, disposing and set it = nothing, in Form1 code!

    2) You can load the value as you are trying, but probably it failed because you forgot to declare your Form1(2,3,4 and 5), as PUBLIC in a module, so ModalForm can't reference them.

    More, if you want to refere a variable on another form, you have to declare it as public in the declaration section of the form, then you can refer to it using the form name, if you already can refer form, obviously:

    Frm1.Textbox1.text="Test"

    Excuse me for my confused english. If you need some more detailed explanation.....I'm here.
    Live long and prosper (Mr. Spock)

  5. #5
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    I would probably go back to your interfaces and simply add a new method that allows you to send the data from the calling form to the dialog form.
    Whadayamean it doesn't work....
    It works fine on my machine!

  6. #6
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Actually, after reviewing your code, I realize that the problem lies in the New procedure.

    You have basically replaced the forms existing New sub with yours. Why this doesn't throw an error is something I do not yet understand. But what is happening is, your InitializeComponent() method is never getting called so your form has no components on it.

    Try adding InitializeComponent() to your New procedure.

    VB Code:
    1. Sub New(ByVal sql As String)
    2.         InitializeComponent()
    3.         m_Sql = sql
    4.     End Sub
    Whadayamean it doesn't work....
    It works fine on my machine!

  7. #7
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    If CyberHawke's suspicion is right you probably have to write something like:


    Public Sub New()
    MyBase.New()
    InitializeComponent()
    ...your instruction here ......
    End Sub

    I supposed you have omitted those two lines .

    Anyway is not necessary overload the builder, you can write in ModalForm controls after it is instanced, and than you can read from them when it return to yopur application. Modal Form are made to obtain this result easily!
    Good job
    Live long and prosper (Mr. Spock)

  8. #8
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    I ran a test, the MyBase.New() was not necessary, but it probably is a good idea anyway
    Whadayamean it doesn't work....
    It works fine on my machine!

  9. #9

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    Originally posted by CyberHawke
    Actually, after reviewing your code, I realize that the problem lies in the New procedure.

    You have basically replaced the forms existing New sub with yours. Why this doesn't throw an error is something I do not yet understand. But what is happening is, your InitializeComponent() method is never getting called so your form has no components on it.

    Try adding InitializeComponent() to your New procedure.

    VB Code:
    1. Sub New(ByVal sql As String)
    2.         InitializeComponent()
    3.         m_Sql = sql
    4.     End Sub

    Yes, you are right. I had done this already and it worked. Thanks all. So constructor method is probably the best one, after all that is what they are there for.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width