Results 1 to 10 of 10

Thread: problem with ITEMDATA

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2006
    Posts
    977

    problem with ITEMDATA

    Hi
    I have a form that displays records from an SQL table
    the Table is Patron and it contains the following fields:
    ID,CategoryID,SubCategoryID,Name,Date...

    if the record has the following data
    ID=139
    CategoryID=9
    SubCategoryID=12
    Name:John Smith
    when the form loads: (cbocategory is filled with categories from the table Category)
    Rs1.Open"Select*from Category ORDER BY CategoryID"
    Rs1.MoveFirst
    Do while Not Rs1.EOF
    cbocategory.AddItem Rs1!ArticleCategory
    cbocategory.Item
    Data(cbocategory.NewIndex)=Rs1!CategoryID
    Rs1.movenext
    loop
    Rs1.close

    so the form should display the category which has its itemdata=CategoryID,for example if the category"Economics" has an itemdata=9 and the current record has a CategoryId=9 so the form should highlight the category"Economics" in the category combobox(cbocategory).how can i do it?

  2. #2
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: problem with ITEMDATA

    try
    cbocategory.listindex = Rs1!CategoryID
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,175

    Re: problem with ITEMDATA

    Quote Originally Posted by engnouna
    Hi
    I have a form that displays records from an SQL table
    the Table is Patron and it contains the following fields:
    ID,CategoryID,SubCategoryID,Name,Date...

    if the record has the following data
    ID=139
    CategoryID=9
    SubCategoryID=12
    Name:John Smith
    when the form loads: (cbocategory is filled with categories from the table Category)
    Rs1.Open"Select*from Category ORDER BY CategoryID"
    Rs1.MoveFirst
    Do while Not Rs1.EOF
    cbocategory.AddItem Rs1!ArticleCategory
    cbocategory.Item
    Data(cbocategory.NewIndex)=Rs1!CategoryID
    Rs1.movenext
    loop
    Rs1.close

    so the form should display the category which has its itemdata=CategoryID,for example if the category"Economics" has an itemdata=9 and the current record has a CategoryId=9 so the form should highlight the category"Economics" in the category combobox(cbocategory).how can i do it?
    What are you trying to do with that line?

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2006
    Posts
    977

    Re: problem with ITEMDATA

    Hi MartinLiss
    With the following code:
    cbocategory.AddItem Rs1!ArticleCategory
    cbocategory.ItemData(cbocategory.NewIndex)=Rs1!CategoryID
    I add The ArticleCategory from the table Category to the combobox cbocategory and I assign it's ItemData to CategoryID
    For example if I have in the table Category
    Category="Economics"
    CategoryID=9
    so i add Economics to cbocategory and I assign its ItemData=9
    if I want to send it to a table Patron that has CategoryID as a field,so I do the following
    Rs1!CategoryID=cbocategory.ItemData(cbocategory.listindex)

  5. #5

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: problem with ITEMDATA

    so the form should display the category which has its itemdata=CategoryID,for example if the category"Economics"
    Loop through the list until you find a match.

    VB Code:
    1. For lngIdx = 0 to cboCategory.ListCount - 1
    2.    If cboCategory.ItemData(lngIdx) = rsPatron.Fields("CategoryId").Value then
    3.        cboCategory.ListIndex = lngIdx
    4.        Exit For
    5.    End If
    6. Next

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2006
    Posts
    977

    Re: problem with ITEMDATA

    well
    i think that cbocategory.ItemData(cbocategory.NewIndex)=Rs1!CategoryID
    assigns the categoryID of the current category to its itemdata and not it will highlight the category that has its itemdata=categoryID.
    isn't it?

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2006
    Posts
    977

    Re: problem with ITEMDATA

    hi brucevde
    i tried the same code but it didn't work?
    how should i declare lngIdx?long or integer???

  9. #9
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: problem with ITEMDATA

    I always use a Long for Looping but it should not matter in this case. There is no reason that code would fail to find the ItemData if it exists.

  10. #10

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