Solved

Display comboxes created at runtime

Posted on 2011-03-10
5
310 Views
Last Modified: 2013-11-27
I am generating comboboxes as:
 Public Combos() As ComboBox
later I use:
 ReDim Combos(5)
      For J = 0 To 5
         Combos(J) = New ComboBox
      Next
I use Combos(0).Items.Add(Item) for example to populate them.
However I cannot display the comboboxes on the form.
What is missing?
0
Comment
Question by:hlominac
  • 2
  • 2
5 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 35094166
You still need to place them somewhere on the form (through coding)

Example:

For J = 0 To 5
         ComboBox x = New ComboBox
         x.Size = New System.Drawing.Size(60, 15)  
         x.Location = New System.Drawing.Point(30 * J, 200)  
         Me.Controls.Add(x)  
         Combos(J) = x
      Next


http://www.dreamincode.net/forums/topic/63445-dynamic-form-and-controls-generation/
0
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 35094192
This Article may help you in creating dynamic combobox in windows form:-

http://aspalliance.com/1385_Building_Dynamic_NET_Controls_with_Windows_Forms.2
0
 

Author Comment

by:hlominac
ID: 35095944
Dhaest:,
When I ran your code I got an error message at: Me.Controls.Add(x)  
Controls is not a member of MyProgram.Data where Data is the subroutine containing the code.
How do I declare Controls?
Harold
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 35106155
I see, you are creating the controls on a class.

When you call this class, you probably return the array of the comboboxes. In that case, you'll need to loop over this array and place them in your form.

Small example below
// This is your form-code
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim x As New MyProgram
        Dim combos() As ComboBox
        combos = x.GetCombos()

        Dim j As Integer = 0
        For Each combo In combos
            combo.Size = New System.Drawing.Size(60, 15)
            combo.Location = New System.Drawing.Point(30, 30 * j)
            j += 1
            Me.Controls.Add(combo)
        Next
    End Sub
End Class


// This is your class code
Public Class MyProgram

    Public Function GetCombos() As ComboBox()
        Dim Combos(5) As ComboBox
        ReDim Combos(5)
        For J = 0 To 5
            Combos(J) = New ComboBox
        Next
        Return Combos
    End Function


End Class

Open in new window

0
 

Author Closing Comment

by:hlominac
ID: 35127587
Using your example I learned a lot about creating in runtime.  Thank you!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question