Move Up and down CheckedListBox items ?

Posted on 2006-04-03
Last Modified: 2008-01-09

Hi to All .NET Experts,

I' using VB .NET contains CheckedListBox control, this control has alot of items
I have 2 buttons onr to move up the selected item and the other move it to down .

How can I do it plz ,
Question by:basheer_basata
    LVL 96

    Accepted Solution

    Try this:

      Public Sub MoveItem(ByVal list As ListBox, ByVal direction As Integer)

        If (direction = -1 And list.SelectedIndex > 0) Or _
         (direction = 1 And list.SelectedIndex < list.Items.Count - 1) Then

          Dim index As Integer = list.SelectedIndex
          Dim value As String = list.Items(index)

          list.Items.Insert(index + direction, value)
        End If

      End Sub

    LVL 96

    Expert Comment

    by:Bob Learned

      Me.CheckedListBox1.Items.AddRange(New String() {"Test 1", "Test 2", "Test 3"})
      Me.CheckedListBox1.SelectedIndex = 0
      MoveItem(Me.CheckedListBox1, 1)
      Me.CheckedListBox1.SelectedIndex = 2
      MoveItem(Me.CheckedListBox1, -1)


    Author Comment

    Dear Bob ,

    It is CheckedListBox not ListBox

    LVL 96

    Expert Comment

    by:Bob Learned

    There is some magic going on there.  CheckedListBox inherits from ListBox, so you can always cast a CheckedListBox down to a ListBox.  In this way, you don't have to have a different method for each type (CheckedListBox and ListBox).  Try it with the CheckedListBox, and it will work just fine.


    Author Comment

    Dear Bob ,

    You are right =)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now