Dynamically creating combobox with Style=2 - Dropdown List?
Author |
Message |
Mark Esse #1 / 10
|
 Dynamically creating combobox with Style=2 - Dropdown List?
We are creating controls dynamically in our application, and when you create a combobox control dynamically, the default style = 0(Dropdown Combo). Is there a way to dynamically create a control with the default style = 2(Dropdown List). Since you can't set this property at Runtime, we need another way to 'default' this style at creation. I have investigated using Windows Hooks(VBPJ - July 1999) to change the style at Creation time, as that is probably when it needs to be done, but can't seem to set this style. Has anybody done this? TIA, Mark Essex
|
Mon, 17 Dec 2001 03:00:00 GMT |
|
 |
Frank Car #2 / 10
|
 Dynamically creating combobox with Style=2 - Dropdown List?
Quote:
>We are creating controls dynamically in our application, and when you create >a combobox control dynamically, the default style = 0(Dropdown Combo). Is >there a way to dynamically create a control with the default style = >2(Dropdown List). Since you can't set this property at Runtime, we need >another way to 'default' this style at creation.
The easy way is to simply build a user control that has a style 2 combo box as a constituent control. All you would have to do is mirror the properties. Yes, there is a slight memory/performance hit in doing this, but if dynamic is your primary concern, then it isn't a major problem. I have a "Swiss Army Knife" control that not only has this kind of combo, but a textbox, listbox, date selection, and a few others in it. This allows my main "shell" program to use it to build out forms based on definitions stored in a database. If it didn't have this functionality, I would have had to have written and distributed 40 or so similar applications. If you want to pursue the more difficult method, I think you're on the right track. Keep it mind that it is a difficult endeavor. Frank Carr
|
Mon, 17 Dec 2001 03:00:00 GMT |
|
 |
Jeff Abbbot #3 / 10
|
 Dynamically creating combobox with Style=2 - Dropdown List?
Mark, I am generateing controls run-time as well. However, I have not experienced a problem with chaging the style during run-time. Don't know what version of VB you are using, but I found that I had to add my controls in the form's initialize event or they would not display properly. In this event I also set the style property without any problems.
|
Mon, 17 Dec 2001 03:00:00 GMT |
|
 |
Jeff Ashle #4 / 10
|
 Dynamically creating combobox with Style=2 - Dropdown List?
Quote: >The easy way is to simply build a user control that has a style 2 combo box >as a constituent control. All you would have to do is mirror the properties. >Yes, there is a slight memory/performance hit in doing this
Au contraire, mon ami! 'Loading' - which is really cloning - an additional member of a control array is a far faster and more efficient method of adding a control at run-time than is Controls.Add . . .
|
Mon, 17 Dec 2001 03:00:00 GMT |
|
 |
Frank Car #5 / 10
|
 Dynamically creating combobox with Style=2 - Dropdown List?
Quote:
>Au contraire, mon ami! 'Loading' - which is really cloning - an additional >member of a control array is a far faster and more efficient method of adding a >control at run-time than is Controls.Add . . .
The speed hit I'm talking about comes from the overhead of loading a user control with about a dozen constituent controls, not from the loading method. Therefore, I'm cloning 13 controls rather than just one, thus the extra processing overhead. In the app I mentioned, I am using the Load method, not the Controls.Add method. I have the typical "zero/template" element that's never used and I load the controls from there. Fields in the database determines load order and placement of the controls. Frank Carr
|
Tue, 18 Dec 2001 03:00:00 GMT |
|
 |
Jeff Ashle #6 / 10
|
 Dynamically creating combobox with Style=2 - Dropdown List?
Okay, we've gone from one style-2 combo box to a user control with 13 controls on it . . . You're right, your method does seem exorbitant in terms of resources, but (1) do you really notice the time expended in cloning this user control, (2) what is the cost of loading via Controls.Add a single combo box in comparison to the time you are spending, and (3) how quickly is any time-savings from using Controls.Add expended in late-binding references? Quote:
> >Au contraire, mon ami! 'Loading' - which is really cloning - an additional > >member of a control array is a far faster and more efficient method of > adding a > >control at run-time than is Controls.Add . . . > The speed hit I'm talking about comes from the overhead of loading a user > control with about a dozen constituent controls, not from the loading > method. Therefore, I'm cloning 13 controls rather than just one, thus the > extra processing overhead. > In the app I mentioned, I am using the Load method, not the Controls.Add > method. I have the typical "zero/template" element that's never used and I > load the controls from there. Fields in the database determines load order > and placement of the controls. > Frank Carr
|
Tue, 18 Dec 2001 03:00:00 GMT |
|
 |
Tarek Haoul #7 / 10
|
 Dynamically creating combobox with Style=2 - Dropdown List?
There is no way to do what you are asking without recreating the control from scratch, this is just the nature of the combo box, a usercontrol wont help either cause the Combo box already. The Windows Hook aspect sounds like the way to proceed, thats if you can get it to work. Tarek
Quote: > We are creating controls dynamically in our application, and when you create > a combobox control dynamically, the default style = 0(Dropdown Combo). Is > there a way to dynamically create a control with the default style = > 2(Dropdown List). Since you can't set this property at Runtime, we need > another way to 'default' this style at creation. > I have investigated using Windows Hooks(VBPJ - July 1999) to change the > style at Creation time, as that is probably when it needs to be done, but > can't seem to set this style. > Has anybody done this? > TIA, > Mark Essex
|
Thu, 20 Dec 2001 03:00:00 GMT |
|
 |
Mark Esse #8 / 10
|
 Dynamically creating combobox with Style=2 - Dropdown List?
Actually, the user control worked very well. I just set the DataCombo Style property = 2 on the user control BEFORE I compiled the user control into an OCX. So, when the user control is created, either dynamically, or by being drawn on the screen, it has a style = 2. So, my user control is used to dynamically create combo boxes with Style = 2. I couldn't use it to create dynamic combos of style = 0 or style = 1 for the same reason as the original problem presented. So, I have decided to go with this method, as it was pretty simple to implement, and works like a champ. Thanks to all that contributed answers to this thread... Mark
Quote: > There is no way to do what you are asking without recreating the control > from scratch, this is just the nature of the combo box, a usercontrol wont > help either cause the Combo box already. > The Windows Hook aspect sounds like the way to proceed, thats if you can get > it to work. > Tarek
> > We are creating controls dynamically in our application, and when you > create > > a combobox control dynamically, the default style = 0(Dropdown Combo). Is > > there a way to dynamically create a control with the default style = > > 2(Dropdown List). Since you can't set this property at Runtime, we need > > another way to 'default' this style at creation. > > I have investigated using Windows Hooks(VBPJ - July 1999) to change the > > style at Creation time, as that is probably when it needs to be done, but > > can't seem to set this style. > > Has anybody done this? > > TIA, > > Mark Essex
|
Sat, 22 Dec 2001 03:00:00 GMT |
|
 |
#9 / 10
|
 Dynamically creating combobox with Style=2 - Dropdown List?
|
Fri, 19 Jun 1992 00:00:00 GMT |
|
 |
ted_willi.. #10 / 10
|
 Dynamically creating combobox with Style=2 - Dropdown List?
I am working on a similar project but having a different problem. I am creating forms dynamically. But I get my initial setting for the dynamic form from an existing form. After scraping the form, I remove it from my project and create it from the database entries. My problem is that I cannot scrape the datasource property. I create a new instance of the target form and loop thru the controls. When I try to read the datasource property, I don't get anything. No object ref. When I perform the same loop in the form_load event, I can reference the datasource property with no problem. Sent via Deja.com http://www.deja.com/ Share what you know. Learn what you don't.
|
Mon, 24 Dec 2001 03:00:00 GMT |
|
|
|