Combo.ItemData maximum value
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: Combo.ItemData maximum value

  1. #1
    Join Date
    Apr 2012
    Posts
    5

    Combo.ItemData maximum value

    Hi all
    First of all, sorry for my poor english writing.
    My question is:
    Why I can NOT set the value "11001000000" to one of combo items as its ItemData value?

    I mean:

    With Recordset1
    .Sort = "ID Asc"
    .MoveFirst
    While Not .EOF
    sItem = .Fields("Code") & " - " & .Fields("Name")
    Combo1.AddItem (sItem)
    Combo1.ItemData(Combo1.NewIndex) = .Fields("ID")
    .MoveNext
    Wend
    End With
    Now, VB 6.0 compiler shows me "Overflow 6" error message for the line "Combo1.ItemData(Combo1.NewIndex) = .Fields("ID") " when .Fields("ID") has the value equal to 11001000000.

    How can I solve this problem?

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,722

    Re: Combo.ItemData maximum value

    If the value in ID is meant to be a decimal numeric, it overflows the ItemData() capacity, which, as far as I know, is limited to Long, that is +/- 2^31
    The value of 11001000000 can be represented by a Double.
    The first idea come to mind is, you have to maintain a (dynamic) array of Doubles which holds the ID.

  3. #3
    Join Date
    Apr 2012
    Posts
    5

    Re: Combo.ItemData maximum value

    Thank you WoF for your attention,

    But how can I use the dynamic array that you said with the combo that has been filled by a recordset?

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,998

    Re: Combo.ItemData maximum value

    What's the data type in the DB? That's what you'd change.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Apr 2012
    Posts
    5

    Re: Combo.ItemData maximum value

    @dglienna:
    Well, as I mentioned in my first post, the recordset which my combo will be filled by has 3 column: ID (bigint) , Name (varchar(50)) and code (char(9)).

    The combo will be filled by it in order that ID will be itemData of every item and I use Code+ --+Name as displayValue
    but it seems that the value
    11001000000
    can not be set as itemdata

    how can I solve this problem?

    thank you

  6. #6
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,998

    Re: Combo.ItemData maximum value

    How can it fit in 9 characters?

    11 001 000 000
    Looks like 11 to me
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Apr 2012
    Posts
    5

    Re: Combo.ItemData maximum value

    @ dglienna:
    11001000000 is not code. It's ID which will be used as itemdata of every item in combo.

  8. #8
    Join Date
    Sep 2006
    Posts
    635

    Re: Combo.ItemData maximum value

    Hi odiseh

    property ItemData is datatype Long, the value that you want to set it's not posible

    11001000000 is out range to Long.
    so I time ago used work :

    Code:
    With Recordset1
                .Sort = "ID Asc"
                .MoveFirst
                While Not .EOF
                    sItem = .Fields("Code") & " - " & .Fields("Name")
                    Combo1.AddItem (sItem)
                     
                       if combo1.tag="" then
                          combo1.tag=cstr( .Fields("ID"))
                       else
                          combo1.tag=combo1.tag & "," & cstr( .Fields("ID"))
                       end if
                    .MoveNext
                Wend
    End With

    and you could get to get the value as :
    Code:
    dim v() as string
    v = Split(combo1.tag, ",")
    Debug.Print v(combo1.ListIndex)
    I hope this is useful

  9. #9
    Join Date
    Apr 2012
    Posts
    5

    Re: Combo.ItemData maximum value

    @hensa22:
    hi
    Thanks alot for your attention. Your solution seems to be correct and is a nice way. I'll try it in my project. Thank you very much
    Last edited by odiseh; April 9th, 2012 at 06:46 AM.

  10. #10
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,722

    Re: Combo.ItemData maximum value

    Nice idea, yes. Only watch that you don't use the .Sort option in the Combobox, because this will then mix up the relation item<->ID

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center