Custom control is inserting its own code?

  • Thread starter Thread starter Fred Flintstone
  • Start date Start date
F

Fred Flintstone

I'm creating a multi-column dropdown since there isn't one. My idea
is to override an Infragistics Combo and add the dropdown as a grid
object. So I create a basic override of the control. The first thing
I want the control to do is kill the default button and add a new one.
So in the initialization (New) area of the control I add the code to
do that:

Me.DropDownButtonDisplayStyle =
Infragistics.Win.ButtonDisplayStyle.Never
Dim Button As New
Infragistics.Win.UltraWinEditors.EditorButton
Button.Key = "Drop"
Button.Visible = True
Button.Enabled = True
Button.Text = "..."
Me.ButtonsRight.Add(Button)

Fairly simple. I build that and load up a new project. I add the new
control in design view and run. I get an error saying "Key already
exists" (each button requires a unique key).

When I look at the "Form Designer Generated Code", it contains this:

EditorButton1.Key = "Drop"
EditorButton1.Text = "..."
Me.DropCombo2.ButtonsRight.Add(EditorButton1)

Why is this in my sample application? I added it to the new control's
initialization but it's added to the sample app code when the control
is dropped on the form. Why is the sample application trying to add
the button again? I would have thought the button would be created
ONCE when the control is created (which it is), not again when the
program is run. How do I stop it from adding this control code to the
sample app?

Thanks!
 
Fred,

If you have the Infragistics controls why not just use the UltraCombo? It
is exactly what you have described.

-Sam Matzen
 
Because the UltraCombo and UltraComboEditor require data binding.
I've been through this with Infragistics, they don't have AddItem
controls so I'm forced to butcher my own. ComponentOne has one but
they took our money, offered no support and ignored us. (Stay clear
of C1)

I'd like to know why a custom control copies, exactly, the code from
the control class's New function into the code of the application it's
being used in.

What if you wanted a combo control that was dropped pre-populated
with say, US states? You'd override a combo, add the population code
to the New function of the control class and build to get a DLL. When
you drop the combo on a sample application's form in design view,
it'll be populated with 50 states. Cool. But little do you know,
dropping that control copied the population code from the New method
of the control class to the 'do not modify' section of the sample app.
So when you RUN the sample with that combo on the form, you get 100
states. Once when the control is dropped (we want that) and then
again when the program is run (we don't). If the combo won't accept
duplicates (like unique button keys) you get an error.

Why is the literal code I've placed in control's New function, added
to the application it's being used in? The New code runs twice.
 
Back
Top