Results 1 to 8 of 8

Thread: [RESOLVED] [02/03] List of interface items

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Belgium
    Posts
    68

    Resolved [RESOLVED] [02/03] List of interface items

    Hi,

    Is it possible to get a list containing all the interface objects that contain data? (textboxes, checkboxes, radiobuttons, etc..)

    I'm trying export the current settings in the interface to an xml file, and would like it to be done as dynamicly as possible.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] List of interface items

    You'd have to test the appropriate property of each one yourself, e.g. TextLength, Checked, SelectedIndex, etc. I have posted code in the CodeBank to visit every control on a form or else you could use a recursive method. You would just use If...ElseIf statements and the TypeOf statement to test the type of ech control and then the appropriate property, e.g.
    VB Code:
    1. If TypeOf ctl Is TextBox Then
    2.     If DirectCast(ctl, TextBox).TextLength > 0 Then
    3.         'The TextBox is not empty.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Belgium
    Posts
    68

    Re: [02/03] List of interface items

    Excellent.

    Thanks.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Belgium
    Posts
    68

    Re: [RESOLVED] [02/03] List of interface items

    How can I find a control object when I have only its name?
    For example, I've got a string containing "txtInput", how can I get a handle the txtInput textfield?

    Is there a better way than to loop through each control object and checking its name attribute?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [02/03] List of interface items

    You can use the CallByName Runtime function if you like, but that will require that the control is declared Public. The CallByName function uses late binding.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Belgium
    Posts
    68

    Re: [RESOLVED] [02/03] List of interface items

    This call by name function?

    Doesn't seem relevant.
    It still needs the pointer to the object itself, no?

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [02/03] List of interface items

    CallByName gets the value of a public field, property or function of an object. The form is an object and the TextBox variable is a field.
    VB Code:
    1. Dim tb As TextBox = DirectCast(CallByName(Me, "TextBox1", CallType.Get), TextBox)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Belgium
    Posts
    68

    Re: [RESOLVED] [02/03] List of interface items

    Ah, I see.
    Thanks.

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