Results 1 to 10 of 10

Thread: Exposing the ItemData property

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Dublin, IRE
    Posts
    111

    Exposing the ItemData property

    Does anyone know the Let/Get Property pair I need to use to expose the ItemData property of a combo control in my user control?

  2. #2
    Addicted Member stevess's Avatar
    Join Date
    May 2001
    Posts
    251
    Put this in a class module (Class1)

    Option Explicit
    Dim mlData As Long

    Public Property Let iData(lItemdata As Long)
    mlData = lItemdata
    End Property
    Public Property Get iData() As Long
    iData = mlData
    End Property

    then in the main form

    Option Explicit
    Public cClass As Class1

    Private Sub Form_Load()
    Set cClass = New Class1

    Combo1.AddItem "test"
    Combo1.ItemData(Combo1.NewIndex) = 99
    Combo1.ListIndex = 0
    cClass.iData = Combo1.ItemData(Combo1.ListIndex)

    End Sub


    form2
    Option Explicit

    Sub Form_Load()
    MsgBox CStr(Form1.cClass.iData)
    End Sub

    I think that is correct.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Dublin, IRE
    Posts
    111
    Stevess, I'm not sure how that helps (although it probably does)

    I've created a user control that has a combobox on it (as part of the control). I'm using it in my form, so in my code, I want to use
    Code:
    combo1.ItemData(combo1.NewIndex) = 1
    as it should be used.

    Unfortunately, niether of these properties are available to me because I haven't exposed them yet. The 'NewIndex' one shouldn't be a problem, but I can't get the ItemData property to appear correctly.

  4. #4
    Addicted Member stevess's Avatar
    Join Date
    May 2001
    Posts
    251
    Sorry, it may not be useful. I am not familiar with creating custom controls that contain other controls. Don't think I can help.

  5. #5
    New Member
    Join Date
    Nov 2011
    Posts
    4

    Re: Exposing the ItemData property

    Hello,

    i have the same problem.
    Does anybody know how to realise this, to bring the combobox property .List and .ItemData to the own UserControl propertys?
    So anybody can use it on my own usercontrol in the same way, than on a combobox control?

    Many thanks.
    Cromit

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Exposing the ItemData property

    Here is a sample generated by the control wizard in VB6
    Code:
    Option Explicit
    'Default Property Values:
    Const m_def_BackColor = 0
    Const m_def_ForeColor = 0
    Const m_def_Enabled = 0
    Const m_def_BackStyle = 0
    Const m_def_BorderStyle = 0
    'Property Variables:
    Dim m_BackColor As Long
    Dim m_ForeColor As Long
    Dim m_Enabled As Boolean
    Dim m_Font As Font
    Dim m_BackStyle As Integer
    Dim m_BorderStyle As Integer
    'Event Declarations:
    Event Click()
    Event DblClick()
    Event KeyDown(KeyCode As Integer, Shift As Integer)
    Event KeyPress(KeyAscii As Integer)
    Event KeyUp(KeyCode As Integer, Shift As Integer)
    Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    
    
    
    'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
    'MemberInfo=8,0,0,0
    Public Property Get BackColor() As Long
        BackColor = m_BackColor
    End Property
    
    Public Property Let BackColor(ByVal New_BackColor As Long)
        m_BackColor = New_BackColor
        PropertyChanged "BackColor"
    End Property
    
    'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
    'MemberInfo=8,0,0,0
    Public Property Get ForeColor() As Long
        ForeColor = m_ForeColor
    End Property
    
    Public Property Let ForeColor(ByVal New_ForeColor As Long)
        m_ForeColor = New_ForeColor
        PropertyChanged "ForeColor"
    End Property
    
    'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
    'MemberInfo=0,0,0,0
    Public Property Get Enabled() As Boolean
        Enabled = m_Enabled
    End Property
    
    Public Property Let Enabled(ByVal New_Enabled As Boolean)
        m_Enabled = New_Enabled
        PropertyChanged "Enabled"
    End Property
    
    'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
    'MemberInfo=6,0,0,0
    Public Property Get Font() As Font
        Set Font = m_Font
    End Property
    
    Public Property Set Font(ByVal New_Font As Font)
        Set m_Font = New_Font
        PropertyChanged "Font"
    End Property
    
    'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
    'MemberInfo=7,0,0,0
    Public Property Get BackStyle() As Integer
        BackStyle = m_BackStyle
    End Property
    
    Public Property Let BackStyle(ByVal New_BackStyle As Integer)
        m_BackStyle = New_BackStyle
        PropertyChanged "BackStyle"
    End Property
    
    'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
    'MemberInfo=7,0,0,0
    Public Property Get BorderStyle() As Integer
        BorderStyle = m_BorderStyle
    End Property
    
    Public Property Let BorderStyle(ByVal New_BorderStyle As Integer)
        m_BorderStyle = New_BorderStyle
        PropertyChanged "BorderStyle"
    End Property
    
    'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
    'MemberInfo=5
    Public Sub Refresh()
         
    End Sub
    
    'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
    'MappingInfo=Combo1,Combo1,-1,ItemData
    Public Property Get ItemData(ByVal Index As Integer) As Long
        ItemData = Combo1.ItemData(Index)
    End Property
    
    Public Property Let ItemData(ByVal Index As Integer, ByVal New_ItemData As Long)
        Combo1.ItemData(Index) = New_ItemData
        PropertyChanged "ItemData"
    End Property
    
    'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
    'MappingInfo=Combo1,Combo1,-1,List
    Public Property Get List(ByVal Index As Integer) As String
        List = Combo1.List(Index)
    End Property
    
    Public Property Let List(ByVal Index As Integer, ByVal New_List As String)
        Combo1.List(Index) = New_List
        PropertyChanged "List"
    End Property
    
    'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
    'MappingInfo=Combo1,Combo1,-1,ListCount
    Public Property Get ListCount() As Integer
        ListCount = Combo1.ListCount
    End Property
    
    'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
    'MappingInfo=Combo1,Combo1,-1,ListIndex
    Public Property Get ListIndex() As Integer
        ListIndex = Combo1.ListIndex
    End Property
    
    Public Property Let ListIndex(ByVal New_ListIndex As Integer)
        Combo1.ListIndex() = New_ListIndex
        PropertyChanged "ListIndex"
    End Property
    
    'Initialize Properties for User Control
    Private Sub UserControl_InitProperties()
        m_BackColor = m_def_BackColor
        m_ForeColor = m_def_ForeColor
        m_Enabled = m_def_Enabled
        Set m_Font = Ambient.Font
        m_BackStyle = m_def_BackStyle
        m_BorderStyle = m_def_BorderStyle
    End Sub
    
    'Load property values from storage
    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    Dim Index As Integer
    
        m_BackColor = PropBag.ReadProperty("BackColor", m_def_BackColor)
        m_ForeColor = PropBag.ReadProperty("ForeColor", m_def_ForeColor)
        m_Enabled = PropBag.ReadProperty("Enabled", m_def_Enabled)
        Set m_Font = PropBag.ReadProperty("Font", Ambient.Font)
        m_BackStyle = PropBag.ReadProperty("BackStyle", m_def_BackStyle)
        m_BorderStyle = PropBag.ReadProperty("BorderStyle", m_def_BorderStyle)
    'TO DO: The member you have mapped to contains an array of data.
    '   You must supply the code to persist the array.  A prototype
    '   line is shown next:
        Combo1.ItemData(Index) = PropBag.ReadProperty("ItemData" & Index, 0)
    'TO DO: The member you have mapped to contains an array of data.
    '   You must supply the code to persist the array.  A prototype
    '   line is shown next:
        Combo1.List(Index) = PropBag.ReadProperty("List" & Index, "")
        Combo1.ListIndex = PropBag.ReadProperty("ListIndex", 0)
    End Sub
    
    'Write property values to storage
    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    Dim Index As Integer
    
        Call PropBag.WriteProperty("BackColor", m_BackColor, m_def_BackColor)
        Call PropBag.WriteProperty("ForeColor", m_ForeColor, m_def_ForeColor)
        Call PropBag.WriteProperty("Enabled", m_Enabled, m_def_Enabled)
        Call PropBag.WriteProperty("Font", m_Font, Ambient.Font)
        Call PropBag.WriteProperty("BackStyle", m_BackStyle, m_def_BackStyle)
        Call PropBag.WriteProperty("BorderStyle", m_BorderStyle, m_def_BorderStyle)
    'TO DO: The member you have mapped to contains an array of data.
    '   You must supply the code to persist the array.  A prototype
    '   line is shown next:
        Call PropBag.WriteProperty("ItemData" & Index, Combo1.ItemData(Index), 0)
    'TO DO: The member you have mapped to contains an array of data.
    '   You must supply the code to persist the array.  A prototype
    '   line is shown next:
        Call PropBag.WriteProperty("List" & Index, Combo1.List(Index), "")
        Call PropBag.WriteProperty("ListIndex", Combo1.ListIndex, 0)
    End Sub

  7. #7
    New Member
    Join Date
    Nov 2011
    Posts
    4

    Re: Exposing the ItemData property

    Many thanks for this very quick response.
    I used also the control wizard of VB6 to test it.
    But in my project i don't see the property List and ItemData in the control property list!?

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Exposing the ItemData property

    If you have the combo box on your control before you execute the wizard you should have a list on the left which contains these properties and one on the right which does not. You just need to select them one by one on the left then add them to the list on the right with the button provided.

  9. #9
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Exposing the ItemData property

    This should give you enough to add and use the ItemData in your control.

    Control Code
    Code:
    Option Explicit
    
    Public Event Click()
    
    Private Sub Combo1_Click()
        RaiseEvent Click
    End Sub
    
    Public Sub AddItem(ByVal Item As String, Optional ByVal Index As Integer = -1)
        If Index > -1 Then
            Combo1.AddItem Item, Index
        Else
            Combo1.AddItem Item
        End If
    End Sub
    
    Public Property Get ItemData(ByVal Index As Integer) As Long
        ItemData = Combo1.ItemData(Index)
    End Property
    
    Public Property Let ItemData(ByVal Index As Integer, ByVal New_ItemData As Long)
        Combo1.ItemData(Index) = New_ItemData
    End Property
    
    Public Property Get NewIndex() As Integer
        NewIndex = Combo1.NewIndex
    End Property
    
    Public Property Get ListIndex() As Integer
        ListIndex = Combo1.ListIndex
    End Property
    
    Public Property Let ListIndex(ByVal New_ListIndex As Integer)
        Combo1.ListIndex = New_ListIndex
    End Property
    
    Public Property Get Text() As String
        Text = Combo1.Text
    End Property
    
    Public Property Let Text(ByVal New_Text As String)
        Combo1.Text() = New_Text
    End Property
    Form code to use the control
    Code:
    Private Sub Form_Load()
        UserControl11.AddItem "First Entry"
        UserControl11.ItemData(UserControl11.NewIndex) = 5
        
        UserControl11.AddItem "Second Entry"
        UserControl11.ItemData(UserControl11.NewIndex) = 50
        
        UserControl11.AddItem "Third Entry"
        UserControl11.ItemData(UserControl11.NewIndex) = 500
        
    End Sub
    
    Private Sub UserControl11_Click()
        MsgBox UserControl11.Text & " ItemData = " & UserControl11.ItemData(UserControl11.ListIndex)
    End Sub

  10. #10
    New Member
    Join Date
    Nov 2011
    Posts
    4

    Re: Exposing the ItemData property

    Thank you.
    Your sample works.

    But, I can't see the propertys "List" and "ItemData" in developing time in the IDE!?
    It works only in run time.

    But I need to fill the List and ItemData in developing time in the IDE,
    as it works with the standard ComboBox.
    How I realize this?

    Many thanks for any help.

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