Results 1 to 11 of 11

Thread: Absolute beginner's question

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Location
    el cajon, ca
    Posts
    1
    I want to allow a user to reorder items in a listbox. For example, clicking on a button should move the currently selcted item in a listbox up one position in the list. It should remain selected so that the user can contiune clicking the button repeatedly.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Code:
    Private Sub List1_Click()
    
    Dim strTemp As String
    
      strTemp = List1.List(List1.ListIndex)
    
      List1.RemoveItem List1.ListIndex
    
      List1.AddItem strTemp,0
    
      List1.Selected(0) = True
    
    End Sub
    there's probably a faster way, but its late
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    lol. that code doesnt work.

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Yawn... *streches a little...*

    what part doesn't work? I'm not looking at VB right now...
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033
    with this code the selected item goes to the top of the list...
    Help keep this forum clean: Remember to mark your thread as resolved · Search before you post · Remember to rate posts that help

    VS2010: Visual Studio 2010 Keybinding Posters
    · Service Pack 1
    Tools: GhostDoc - automatically generates XML documentation comments
    · NuGet package Manager · PowerCommands IDE extensions
    Source Control: ankhsvn - integration for SVN
    · Windows Shell Extension for Subversion

    Development Laptop: Intel Core i5 430M 2.26 GHz @ 2.53 GHz
    · 4096 MB, DDR3 PC3-8500F (533 MHz), Kingston · ATI Mobility Radeon HD 5470 · 15.6 @ 16:9, 1366x768 pixel, HD LED LCD

    I follow:
    JoelOnSoftware - A weblog by Joel Spolsky, a programmer working in New York City, about software and software companies
    ScottGu's Blog - Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework
    Portugal-a-Programar - Portuguese Developers Community
    .NET Rocks! - is a weekly Internet audio talk show for .NET Developers.

    Programming Languages:
    C#
    · VB.NET · JAVA · PHP · Javascript
    Other:
    XML
    · HTML · CSS · JQuery · SQL



    *** Proudly Portuguese ***

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    damn, I gotta learn to read better, I thought thats what he was looking for, my mistake...
    Code:
    Private Sub List1_Click()
    
    Dim strTemp As String
    Dim intPos As Integer
    
      strTemp = List1.List(List1.ListIndex)
      intPos = List1.ListIndex - 1
    
      List1.RemoveItem List1.ListIndex
    
      If intPos >= 0 Then
        List1.AddItem strTemp,intPos
        List1.Selected(intPos) = True
      Else
        List1.AddItem strTemp,0
        List1.Selected(0) = True
      End If
    
      
    
    End Sub
    does that work guys?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  7. #7
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033
    it works with one correction, sorry man, ... who am i to correct you...



    Private Sub Command1_Click()
    Dim strTemp As String
    Dim intPos As Integer

    strTemp = List1.List(List1.ListIndex)
    intPos = List1.ListIndex - 1

    List1.RemoveItem List1.ListIndex

    If intPos >= 0 Then
    List1.AddItem strTemp, intPos
    List1.Selected(intPos) = True
    Else
    List1.AddItem strTemp, 0
    List1.Selected(0) = True
    End If
    End Sub





    use a command_click event instead of a list_click event or you will get a "Out of stack space" error
    Help keep this forum clean: Remember to mark your thread as resolved · Search before you post · Remember to rate posts that help

    VS2010: Visual Studio 2010 Keybinding Posters
    · Service Pack 1
    Tools: GhostDoc - automatically generates XML documentation comments
    · NuGet package Manager · PowerCommands IDE extensions
    Source Control: ankhsvn - integration for SVN
    · Windows Shell Extension for Subversion

    Development Laptop: Intel Core i5 430M 2.26 GHz @ 2.53 GHz
    · 4096 MB, DDR3 PC3-8500F (533 MHz), Kingston · ATI Mobility Radeon HD 5470 · 15.6 @ 16:9, 1366x768 pixel, HD LED LCD

    I follow:
    JoelOnSoftware - A weblog by Joel Spolsky, a programmer working in New York City, about software and software companies
    ScottGu's Blog - Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework
    Portugal-a-Programar - Portuguese Developers Community
    .NET Rocks! - is a weekly Internet audio talk show for .NET Developers.

    Programming Languages:
    C#
    · VB.NET · JAVA · PHP · Javascript
    Other:
    XML
    · HTML · CSS · JQuery · SQL



    *** Proudly Portuguese ***

  8. #8
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by zuperman
    it works with one correction, sorry man, ... who am i to correct you...
    I make mistakes like everybody. Thanks for pointing that out
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  9. #9
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    hehe

    I like correcting him! It makes my lameass feel better about my self!

    Just kidding!! hehe

  10. #10
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033
    Help keep this forum clean: Remember to mark your thread as resolved · Search before you post · Remember to rate posts that help

    VS2010: Visual Studio 2010 Keybinding Posters
    · Service Pack 1
    Tools: GhostDoc - automatically generates XML documentation comments
    · NuGet package Manager · PowerCommands IDE extensions
    Source Control: ankhsvn - integration for SVN
    · Windows Shell Extension for Subversion

    Development Laptop: Intel Core i5 430M 2.26 GHz @ 2.53 GHz
    · 4096 MB, DDR3 PC3-8500F (533 MHz), Kingston · ATI Mobility Radeon HD 5470 · 15.6 @ 16:9, 1366x768 pixel, HD LED LCD

    I follow:
    JoelOnSoftware - A weblog by Joel Spolsky, a programmer working in New York City, about software and software companies
    ScottGu's Blog - Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework
    Portugal-a-Programar - Portuguese Developers Community
    .NET Rocks! - is a weekly Internet audio talk show for .NET Developers.

    Programming Languages:
    C#
    · VB.NET · JAVA · PHP · Javascript
    Other:
    XML
    · HTML · CSS · JQuery · SQL



    *** Proudly Portuguese ***

  11. #11
    New Member
    Join Date
    Oct 2006
    Posts
    1

    Re: Absolute beginner's question

    This Is With Up And Down Buttons With Slight Mods To The Code.

    Private Sub cmdMove_Click(Index As Integer)
    Dim strTemp As String
    Dim intPos As Integer
    Dim MySelectionChecked As Boolean
    '
    If MCListing(1).ListCount > 0 Then
    strTemp = MCListing(1).List(MCListing(1).ListIndex)
    intPos = MCListing(1).ListIndex
    MySelectionChecked = False
    If MCListing(1).Selected(intPos) = True Then
    MySelectionChecked = True
    End If
    If Index = 0 Then
    If intPos - 1 >= 0 Then
    MCListing(1).RemoveItem MCListing(1).ListIndex
    MCListing(1).AddItem strTemp, intPos - 1
    MCListing(1).Selected(intPos - 1) = MySelectionChecked
    End If
    Else
    If intPos + 1 < MCListing(1).ListCount Then
    MCListing(1).RemoveItem MCListing(1).ListIndex
    MCListing(1).AddItem strTemp, intPos + 1
    MCListing(1).Selected(intPos + 1) = MySelectionChecked
    End If
    End If
    End If
    End Sub

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