Results 1 to 6 of 6

Thread: [RESOLVED] Control property like .list ( dropdown )

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Resolved [RESOLVED] Control property like .list ( dropdown )

    All,

    Is there a way to add a property to an activex control that acts like a comboBox's list property ? You know, the dropdown list but in the property box for an activex control.

    I can set a variable type as a filename and get the [...] ,the ole_color color picker and even the font chooser. But no list ?

    Before you ask, I don't have a particular use but if it's possible I could probably think of a few.
    Keith_VB6

    If you have any further questions, just ask.
    If this solves things, then please mark the thread resolved.
    [Thread Tools] --> [Mark Thread Resolved]

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Control property like .list ( dropdown )

    Add a listbox to the conrol.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: Control property like .list ( dropdown )

    Hey Al42,

    I'm actually just wondering if it's possible to add a dropdown property to the controls properties box. Like the combo.list, but more like an actual dropdown. It's like a list of choices but something that's changeable at design time. Like the UpDown control's BuddyProperty.

    I know if you set a properties type in a ActiveX control then the property box for that control reflects that. Like a dropdown with True and False for a Boolean.

    I guess I could always use a Propety Page and add a ComboBox on it and copy the contents or just the selected text to a variable in the control, but I just wondered if there was a more direct way through the props instead of the (custom).
    Attached Images Attached Images  
    Keith_VB6

    If you have any further questions, just ask.
    If this solves things, then please mark the thread resolved.
    [Thread Tools] --> [Mark Thread Resolved]

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Control property like .list ( dropdown )

    Now that I understand what you want, use an Enum in the control and Let/Get something with that Enum.

    VB Code:
    1. Public Enum myProp
    2.   [(Default)]
    3.   Name
    4.   Caption
    5.   Index
    6.   BackColor
    7.   Left
    8.   Top
    9. End Enum
    10.  
    11. Public Property Get EnumThing() As myProp
    12.     EnumThing = m_EnumThing
    13. End Property
    14.  
    15. Public Property Let EnumThing(ByVal New_EnumThing As myProp)
    16.   m_EnumThing = New_EnumThing
    17.   PropertyChanged "EnumThing"
    18. End Property
    I think that's what you want.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: Control property like .list ( dropdown )

    Hey Al42,

    Thanks for the reply.

    Yeah, I know how to use Enum, I was was looking for a way to make the dropdown's list changeable. Once you set a property as a particular type it's stuck that way.

    As I said, I don't currently have a use for it. Although, I'd like to be able to pick something like a list of controls on a form from the dropdown and link it the usercontrol. But that could probably be easier to do in a property sheet. When the property sheet loaded, I could have the control add the controls to a dropdown.

    It's just one of those, can it be done things. You never know when I might need it.

    I'm learning Visual C++. So, maybe there's a way to do it through C++. It seems a more flexible language but it also requires a lot more coding.

    I'll leave this thread unresolved for now, maybe someone will have an idea.Thanks for the help.
    Keith_VB6

    If you have any further questions, just ask.
    If this solves things, then please mark the thread resolved.
    [Thread Tools] --> [Mark Thread Resolved]

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: Control property like .list ( dropdown )

    Ok, I think I got this working through a property page. After crashing the IDE about 20 times.

    Here's my code:
    VB Code:
    1. 'usercontrol module
    2. Public ParentForm As Form
    3. Public ParentControlName As String
    4.  
    5. 'usercontrol code example
    6.  Option Explicit
    7. 'Default Property Values:
    8. Const m_def_LinkIndex = -1
    9. Const m_def_LinkName = 0
    10. 'Property Variables:
    11. Dim m_LinkIndex As Integer
    12. Dim m_LinkName As Variant
    13.  
    14.  
    15. Private Sub Command1_Click()
    16.     If LinkIndex <> -1 Then
    17.         UserControl.Parent.Controls(LinkIndex).Text = "weqweqweqe"
    18.     End If
    19. End Sub
    20.  
    21.  
    22. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    23.     Set ParentForm = UserControl.Parent
    24.     ParentControlName = UserControl.Extender.Name
    25.    
    26.     m_LinkName = PropBag.ReadProperty("LinkName", m_def_LinkName)
    27.     m_LinkIndex = PropBag.ReadProperty("LinkIndex", m_def_LinkIndex)
    28. End Sub
    29. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
    30. 'MemberInfo=14,0,0,0
    31. Public Property Get LinkName() As Variant
    32.     LinkName = m_LinkName
    33. End Property
    34.  
    35. Public Property Let LinkName(ByVal New_LinkName As Variant)
    36.     m_LinkName = New_LinkName
    37.     PropertyChanged "LinkName"
    38. End Property
    39.  
    40. 'Initialize Properties for User Control
    41. Private Sub UserControl_InitProperties()
    42.     m_LinkName = m_def_LinkName
    43.     m_LinkIndex = m_def_LinkIndex
    44. End Sub
    45.  
    46. 'Write property values to storage
    47. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    48.     Call PropBag.WriteProperty("LinkName", m_LinkName, m_def_LinkName)
    49.     Call PropBag.WriteProperty("LinkIndex", m_LinkIndex, m_def_LinkIndex)
    50. End Sub
    51.  
    52. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
    53. 'MemberInfo=7,0,0,-1
    54. Public Property Get LinkIndex() As Integer
    55.     LinkIndex = m_LinkIndex
    56. End Property
    57.  
    58. Public Property Let LinkIndex(ByVal New_LinkIndex As Integer)
    59.     m_LinkIndex = New_LinkIndex
    60.     PropertyChanged "LinkIndex"
    61. End Property
    62.  
    63.  
    64. 'in the property Page
    65. Option Explicit
    66.  
    67. Private Sub List1_Click()
    68.     Changed = True
    69. End Sub
    70.  
    71.  
    72. Private Sub PropertyPage_Initialize()
    73.     On Error GoTo ErrorTrap
    74.     Dim c As Control
    75.     Dim index As Integer
    76.     Dim Count As Integer
    77.    
    78.     List1.Clear
    79.    
    80.     For Each c In ParentForm.Controls 'this variable is set in the usercontrol
    81.         Count = Count + 1
    82.  
    83.         'make sure the control isn't the usercontrol but is a textbox
    84.         If c.Name <> ParentControlName And TypeOf c Is TextBox Then
    85.             'ParentControlName is set in UC
    86.             index = -1
    87.             index = c.index ' part of an array, set to index else after err, index=-1
    88.             If index = -1 Then
    89.                 'control is not part of an array
    90.                 List1.AddItem c.Name
    91.                 List1.ItemData(List1.NewIndex) = Count
    92.             Else
    93.                 'control is part on an array
    94.                 List1.AddItem c.Name & "(" & index & ")"
    95.                 List1.ItemData(List1.NewIndex) = Count
    96.             End If
    97.         End If
    98.     Next c
    99.     Exit Sub
    100. ErrorTrap:
    101.     Resume Next
    102. End Sub
    103.  
    104.  
    105. Private Sub PropertyPage_ApplyChanges()
    106.     SelectedControls(0).LinkName = List1.Text 'this is for show
    107.     SelectedControls(0).LinkIndex = List1.ItemData(List1.ListIndex) - 1 'this is the actual link
    108. End Sub
    Keith_VB6

    If you have any further questions, just ask.
    If this solves things, then please mark the thread resolved.
    [Thread Tools] --> [Mark Thread Resolved]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width