Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

MoveListboxItem - Moving an item of a listbox to another index

Total Hit ( 2561)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
' Moves an item of a listbox to another index
' If FROMINDEX = -1 then it moves the current highlighted item
'
' Example:
'  ' move up the selected item
'  MoveListboxItem(ListBox1, -1, ListBox1.SelectedIndex - 1)
'  ' move down the selected item
'  MoveListboxItem(ListBox1, -1, ListBox1.SelectedIndex + 1)

Sub MoveListboxItem(ByVal ctl As ListBox, ByVal fromIndex As Integer, _
  ByVal toIndex As Integer)
  If fromIndex = toIndex Then Exit Sub
  ' provide a default
  If fromIndex < 0 Then fromIndex = ctl.SelectedIndex
  ' exit if argument not in range
  If toIndex < 0 Or toIndex > ctl.Items.Count - 1 Then Exit Sub

  With ctl
    ' save the data of the current item
    Dim data As Object = .Items(fromIndex)
    ' remove the item
    .Items.RemoveAt(fromIndex)
    ' add the item
    .Items.Insert(toIndex, data)
    ' select the new item
    .SelectedIndex = toIndex
  End With
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.