Detect If Control Contains Property

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Derek Hart

    Detect If Control Contains Property

    How can I detect if a control contains a property. Need to use reflection
    somehow?

    If ctl.ContainsPro perty("Tag") Then ctl.Tag = "some tag information"


  • rowe_newsgroups

    #2
    Re: Detect If Control Contains Property

    On Oct 14, 1:32 pm, "Derek Hart" <derekmh...@yah oo.comwrote:
    How can I detect if a control contains a property. Need to use reflection
    somehow?
    >
    If ctl.ContainsPro perty("Tag") Then ctl.Tag = "some tag information"
    Yes, you can use the <Type>.GetPrope rty(...) to determine if a
    property exists and also to set the value there. If however you are
    just interested with controls, it would be simpler to see if the
    object is a control, and then simply cast it into a control. Then the
    tag property would be available as normal.

    Thanks,

    Seth Rowe [MVP]

    Comment

    • Phill W.

      #3
      Re: Detect If Control Contains Property

      Derek Hart wrote:
      How can I detect if a control contains a property.
      Why do you need to?

      You can /ask/ any Control (or, indeed, any Object) what Type it is, and
      then process it accordingly, as in

      Sub Click( sender as Object e as EventArgs )

      If Typeof sender is CheckBox Then
      With DirectCast( sender, CheckBox )
      .Text = .Text.ToUpper()
      .CheckState = CheckedState.Ch ecked
      End With

      Else If Typeof sender is TextBox Then
      With DirectCast( sender, TextBox )
      .Text = .Text.ToLower()
      End With

      End If
      End Sub
      Need to use reflection somehow?
      If you /really/ must, but it's more difficult and (I would expect) quite
      a bit slower as well.

      HTH,
      Phill W.

      Comment

      Working...