Results 1 to 17 of 17

Thread: [RESOLVED] Listing in list box

  1. #1

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Resolved [RESOLVED] Listing in list box



    I have a issue I've been trying to work out in vb6
    I have a listbox that displayes my records, and I wish to set it to were it will always list from Smallest ID to Largest ID
    Example: If the first IDno. = 101 then Id like it to begin there and list the rest in order 101, 102, 103, ect...
    My problem is if I delete record 101 and then add new ID 101 it will list at the end of the list?
    any suggestions?
    Thanks in advance

  2. #2
    Hyperactive Member Rattled_Cage's Avatar
    Join Date
    Dec 2005
    Posts
    315

    Re: Listing in list box

    are these numbers you want to sort ot a b c etc ? i have a sample of sorting in list boxes with a - z not sure if it any good

  3. #3

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Re: Listing in list box

    Yes,
    I wish it to start from the lowest id number and list accordingly>101,102,103
    and if I delete 102 and later enter a new record with id 102 then it will list back
    between 101 and 103 in order?
    thanks!

  4. #4
    Hyperactive Member Rattled_Cage's Avatar
    Join Date
    Dec 2005
    Posts
    315

    Re: Listing in list box

    might not be what your looking for but i messaged you it
    good luck if someone posts ill sure to copy !

  5. #5

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Re: Listing in list box

    Quote Originally Posted by Rattled_Cage
    might not be what your looking for but i messaged you it
    good luck if someone posts ill sure to copy !
    No message here rattled?
    Please if you have help to offer post it on the page of the question so all who may need can be helped by it
    Last edited by Quizton; Dec 25th, 2005 at 11:32 PM.

  6. #6
    Junior Member
    Join Date
    Dec 2005
    Location
    Surat,India
    Posts
    29

    Re: Listing in list box

    hi
    did u use order by clause in youer query? or just show ur code.
    Virendrasinh Narendrasinh Mahida
    ----------------------------------
    There is Never a WRONG time to do the RIGHT Thing

  7. #7
    Junior Member
    Join Date
    Dec 2005
    Location
    Surat,India
    Posts
    29

    Talking Re: Listing in list box

    Hi
    You can also do it by setting sorted = true of listbox property
    Virendrasinh Narendrasinh Mahida
    ----------------------------------
    There is Never a WRONG time to do the RIGHT Thing

  8. #8

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Re: Listing in list box

    sorted = true in list sorted by a b c in list anyone know how to sort by id?
    thanks

  9. #9
    Junior Member
    Join Date
    Dec 2005
    Location
    Surat,India
    Posts
    29

    Re: Listing in list box

    Have you tried it ??
    Just tried and tell me error if any
    Virendrasinh Narendrasinh Mahida
    ----------------------------------
    There is Never a WRONG time to do the RIGHT Thing

  10. #10

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Re: Listing in list box

    yeah I tried the sorted = true but that will sort the box by name and wish to sort by IDno.

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Listing in list box

    Quote Originally Posted by Quizton
    yeah I tried the sorted = true but that will sort the box by name and wish to sort by IDno.
    Is this a ListBox or a ListView?

    ListBox will only accept a single item, although you can simulate the addition of multiple items.

    Sorting your data should always be done from your SQL query anyway rather than leaving the sorting up to a VB control.

  12. #12

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Re: Listing in list box

    Yes, that is exactly what I am after it is a listbox
    My list box only displays the first and last name of the customer and the textboxes display all there info when I click on there name and I also am able to bring up the data by searching for IDno. But what I am after is a code to be sure this listbox will load the first and last names according to IDno. or Least to greatest?
    example If SalMartinez was ID 101 then he would be the first to be displayed in list, this is how it was at the start but the real issue here is that if I deleted Sals record and then later entered JohnSmith and assigned him Sals old IDno then John will be automaticaly placed at the bottom of list When I would like him to be the first since 101 is the start or primary key and then list accordingly 101,102,103,ect...

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

    Re: Listing in list box

    and then later entered JohnSmith and assigned him Sals old IDno then John will be automaticaly placed at the bottom of list
    How do you add the new item to the list? Are you requerying your database and repopulating the list or simply just using AddItem.

    If you are using the AddItem method you can specify its location within the list.

    List1.AddItem "John", 0 - will place the item at the top of the list.
    List1.AddItem "John", 5 - will insert the item at row # 5

  14. #14

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Re: Listing in list box

    I add with a cmdadd button that just adds to the db
    dbadd = true
    then when I save it repopulates, But I think that if I want it to always populate from least number to largest that I will do this in the list function I have set up but I couldn't find the right way to do this yet?
    list by Id least to greatest, something along those lines not sure but am still lookin?
    thanks

  15. #15

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Re: Listing in list box

    Ok well I searched everywere and it looks like listing these in alphabetical order seems the best way to go. And also I guess this really is not of much importance to my app since I search by ID anyway so Ill mark this as resolved and just sort by alphabetical order for two reasons one it is very easy to do it this way and two it seems the most proffessional way to do this as well listing first and last name in list box alphabeticaly in itself would make it easier to find them since they would be sorted. Not sure why I even wanted to list by IDno in the first place.

  16. #16
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] Listing in list box

    Did you try doing your sort use an SQL ORDER BY prior to loading the listbox?

  17. #17
    Junior Member
    Join Date
    Dec 2005
    Location
    Surat,India
    Posts
    29

    Re: [RESOLVED] Listing in list box

    will u show your code here?
    Virendrasinh Narendrasinh Mahida
    ----------------------------------
    There is Never a WRONG time to do the RIGHT Thing

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