Groups | Blog | Home
all groups > vb.net controls > october 2004 >

vb.net controls : Populating Combo during load of Control


SQLScott
10/8/2004 7:05:03 AM
Forgive me if this seems trivial, but any and all help is greatly
appreciated, and I will attempt to explain this as best I can.

I have created a combo and added a certain number of properties to it. When
I place that combo on a form, I set any number of those properties.

What I would like to happen is during the load of the COMBO BOX, not the
form, I would like to see what properties are set on the combo and populate
the combo with data depending on what properties are set.

Yes, I could do this on the load of the FORM, but then I would have to write
code on each and every FORM_LOAD that I place the combo on.

I know there is not an CONTROL_LOAD method, but is there an equivalent that
I can use so that no matter how many forms I drop this combo on, the code is
already with the combo, and all I have to do is set the properties?

I sincerely hope this made sense.

--
Thanks,

Jared
10/9/2004 2:41:50 PM
I don't think you can do what you're asking, because there isn't an event
inside of a control that fires when it is added to a parent container. You
can use the controladded event in the parent form, but, you are no better
off than form_load.

You can inherit from the combobox and set the additional values when they
are set.
For example, lets say you want to add items to the combo box, but only if
the back color is red. You can set the back color to red, and, in the
property set definition you can provide the additional logic.

I could be wrong, as often I am, but, others will help to point out any
shortfalls in my thinking.
HTH,
Jared

Public Class MyCombo
Inherits ComboBox

Sub New()
MyBase.New()
' Add items to the combo box here.
End Sub

Protected Overrides Sub RefreshItem(ByVal index As Integer)
MyBase.RefreshItem(index)
End Sub

Protected Overrides Sub SetItemsCore(ByVal items As
System.Collections.IList)
MyBase.SetItemsCore(items)
End Sub

Public Overrides Property BackColor() As Color
Get
Return MyBase.BackColor
End Get
Set(ByVal Value As Color)
MyBase.BackColor = Value
If Value.Equals(Color.Red) Then
' Set some additional values for the control.
MsgBox("You choose red")
Else
' Remove items here
End If
End Set
End Property
End Class

[quoted text, click to view]

Jared
10/9/2004 4:22:50 PM
Mick,
Can you elaborate for my benefit? How does this let you know only when a
control has been loaded in a parent container only? Thanks,
Jared

"Mick Doherty"
<EXCHANGE#WITH@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:uAdgoTkrEHA.1036@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]

Jared
10/9/2004 8:47:10 PM
Thanks for the explanation Mick.
Jared

"Mick Doherty"
<EXCHANGE#WITH@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:eUEIznlrEHA.1712@tk2msftngp13.phx.gbl...
[quoted text, click to view]

Mick Doherty
10/9/2004 10:14:01 PM
You could use the OnParentChanged method.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


[quoted text, click to view]


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.742 / Virus Database: 495 - Release Date: 19/08/2004

Mick Doherty
10/10/2004 12:44:38 AM
This was a response to your answer which stated:
[quoted text, click to view]

When you add a control to a container, that controls parent changes from
Nothing (or it's previous container) to the Control that contains it, and it
fires the ParentChanged event and the OnParentChanged method.

\\\
Protected Overrides Sub OnParentChanged(ByVal e As System.EventArgs)
MyBase.OnParentChanged(e)
If Me.Parent Is Nothing Then Return
If Me.DesignMode = False Then
MsgBox(Me.Parent.ToString)
End If
End Sub
///

I'm not exactly sure what Scott is trying to do, but it sounds like he could
even use the New() method of his control.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


[quoted text, click to view]


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.742 / Virus Database: 495 - Release Date: 20/08/2004

SQLScott
10/11/2004 12:57:06 PM
I appreciate all the feedback. Thank you.

I heard that ISupportInitialize might solve my problem. Has anyone used
that? Any thoughts as to how you have used it?

Scott

[quoted text, click to view]
SQLScott
10/12/2004 7:43:02 AM
Just an FYI. The ISupportInitialize did solve my problem and did exactly
what I was looking for. By putting code in the EndInit of the control, it
performed exacly as expected.

Scott

[quoted text, click to view]
AddThis Social Bookmark Button