Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Display comboxes created at runtime

Posted on 2011-03-10
5
Medium Priority
?
320 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

705 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