473,385 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to programmatically add a new ComboBox to a form

aaa
Hello to all,

In an application under VB6, I need to fill some ComboBoxes with data.
However, I don't know in advance how many ComboBoxes I will need. I could
of course create many (maybe 15 or 20) and only use those that I need.

However, I would rather like to programmatically create and them to my form.
How can this be achieved? Also, is there a generic method that could be
used with other objects? (For example, programmatically create new forms.)

Thank you in advance for you help.

John H. Dewbert
jo************@hotmail.com
Jul 17 '05 #1
2 8638
Create a combobox on your form in design view. Assign the index property
the value 0 to turn this into a control array. You can then create new
instances of the combobox in this array on the fly with something like:

Load cboArray(cboArray.Ubound + 1)

Then to refer to this new combobox use cboArray(cboArray.Ubound)

For example to create a column of 10 comboboxes, each with 5 pixels between
them:

Dim ix As Integer

For ix = 1 To 10
Load cboArray(cboArray.Ubound + 1) ' load next combobox

' work with the new combobox
With cboArray(cboArray.Ubound)
.Top = cboArray(cboArray.Ubound - 1).Top + _
cboArray(cboArray.Ubound - 1).Height + _
5 * Screen.TwipsPerPixelY

.Visible = True ' make sure you set this, as otherwise the new
comboboxes might not be visible
End With
Next ix

Don't know about doing forms on the fly though.

Hope this helps,

Adam
"aaa" <jo************@hotmail.com> wrote in message
news:4K*********************@news20.bellglobal.com ...
Hello to all,

In an application under VB6, I need to fill some ComboBoxes with data.
However, I don't know in advance how many ComboBoxes I will need. I could
of course create many (maybe 15 or 20) and only use those that I need.

However, I would rather like to programmatically create and them to my form. How can this be achieved? Also, is there a generic method that could be
used with other objects? (For example, programmatically create new forms.)
Thank you in advance for you help.

John H. Dewbert
jo************@hotmail.com

Jul 17 '05 #2
Thank you for the tip, I think it will solve most of my problems!

John.
"Adam Parkin" <sk****@dfaslk.com> a écrit dans le message de
news:UeEmc.25017$LA4.16360@edtnps84...
Create a combobox on your form in design view. Assign the index property
the value 0 to turn this into a control array. You can then create new
instances of the combobox in this array on the fly with something like:

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jose Michael Meo R. Barrido | last post by:
How to programmatically show the dropdown of a combobox in vb.net? please help.
7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
8
by: Zlatko Matiæ | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
3
by: Tzvika | last post by:
Hi, Is there a way to programmatically add/remove windows components in c# or in any other language What is the API fro that?
6
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox...
0
by: Marco Segurini | last post by:
HI, my form contains a combobox and a propertygrid control. At each string of the combobox is associated an object. When I select a string of the combobox the associated object is selected in...
8
by: hunanwarrior | last post by:
I added textbox controls to a form when user selects amount to create from a combobox as follows: 'Load up the combobox Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As...
8
by: William Foster | last post by:
Good evening all, I am creating a program with the ability to select an option from a ComboBox which will then create a secondary list of options in a CheckedListBox. Previously when I have...
3
by: =?Utf-8?B?Y2RtdW5veg==?= | last post by:
I have created a sub routine to programmatically add an indefinite number of combo boxes to a form. The combo boxes are bound in code to a view for displaying the available options. This routine...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.