473,418 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

changing the order of a listbox


Hi;

I need to change the order of a listbox array from a form app
where I select order up or down.

What's a good way to do that?

Regards;

Segue
Nov 23 '05 #1
6 7186
Hi try this, place two buttons and a listbox on a form, button1.text = UP,
button2.text = DOWN, the listbox should have selectionmode set to one. Now
you can try this code.

Hth Greetz Peter

Private Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
ListBox1.Items.Add("First")
ListBox1.Items.Add("Second")
ListBox1.Items.Add("Third")
ListBox1.Items.Add("Fourth")
ListBox1.Items.Add("Fifth")
ListBox1.Items.Add("Sixth")
ListBox1.Items.Add("Seventh")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Not ListBox1.SelectedItem Is Nothing Then
moveup()
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If Not ListBox1.SelectedItem Is Nothing Then
movedown()
End If
End Sub

Private Sub moveup()
Dim tmpItem1, tmpItem2 As Object
Dim intIndex As Integer
If ListBox1.SelectedIndex > 0 Then
intIndex = ListBox1.SelectedIndex
tmpItem1 = ListBox1.Items.Item(intIndex)
tmpItem2 = ListBox1.Items.Item(intIndex - 1)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.RemoveAt(intIndex - 1)
ListBox1.Items.Insert(intIndex - 1, tmpItem2)
ListBox1.Items.Insert(intIndex - 1, tmpItem1)
ListBox1.SelectedItem = ListBox1.Items.Item(intIndex - 1)
End If
End Sub

Private Sub movedown()
Dim tmpItem1, tmpItem2 As Object
Dim intIndex As Integer
If ListBox1.SelectedIndex < ListBox1.Items.Count - 1 Then
intIndex = ListBox1.SelectedIndex
tmpItem1 = ListBox1.Items.Item(intIndex)
tmpItem2 = ListBox1.Items.Item(intIndex + 1)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.Insert(intIndex, tmpItem2)
ListBox1.Items.Insert(intIndex + 1, tmpItem1)
ListBox1.SelectedItem = ListBox1.Items.Item(intIndex + 1)
End If
End Sub
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"segue" <se***@discussions.microsoft.com> schreef in bericht
news:88**********************************@microsof t.com...

Hi;

I need to change the order of a listbox array from a form app
where I select order up or down.

What's a good way to do that?

Regards;

Segue

Nov 23 '05 #2
Perfect. Thanks so much.

Another question.

I'm using a checkbox list (appname) that has fields associated
with each checkbox list appname. You click a button and I instantiate this
newform where you can choose the order of the fields. Then
I want to reinstantiate the newform with the next checkboxlist's
group of fields so that they can be ordered and then keep going for each
appname so I have a listbox that has a two dimensional array:
(1(appname1), field1)
(1(appname1), field1)
(1(appname1), field1)
(1(appname1), field1)
then appname2:
(1(appname2), field2)
(1(appname2), field2)
(1(appname2), field2)
(1(appname2), field2)

for the next appname and its group and so on.

Can anyone see a good design for this.
of fields and keep them in a listbox arraylist of appname1.

Regards;

Segue

"Peter Proost" wrote:
Hi try this, place two buttons and a listbox on a form, button1.text = UP,
button2.text = DOWN, the listbox should have selectionmode set to one. Now
you can try this code.

Hth Greetz Peter

Private Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
ListBox1.Items.Add("First")
ListBox1.Items.Add("Second")
ListBox1.Items.Add("Third")
ListBox1.Items.Add("Fourth")
ListBox1.Items.Add("Fifth")
ListBox1.Items.Add("Sixth")
ListBox1.Items.Add("Seventh")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Not ListBox1.SelectedItem Is Nothing Then
moveup()
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If Not ListBox1.SelectedItem Is Nothing Then
movedown()
End If
End Sub

Private Sub moveup()
Dim tmpItem1, tmpItem2 As Object
Dim intIndex As Integer
If ListBox1.SelectedIndex > 0 Then
intIndex = ListBox1.SelectedIndex
tmpItem1 = ListBox1.Items.Item(intIndex)
tmpItem2 = ListBox1.Items.Item(intIndex - 1)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.RemoveAt(intIndex - 1)
ListBox1.Items.Insert(intIndex - 1, tmpItem2)
ListBox1.Items.Insert(intIndex - 1, tmpItem1)
ListBox1.SelectedItem = ListBox1.Items.Item(intIndex - 1)
End If
End Sub

Private Sub movedown()
Dim tmpItem1, tmpItem2 As Object
Dim intIndex As Integer
If ListBox1.SelectedIndex < ListBox1.Items.Count - 1 Then
intIndex = ListBox1.SelectedIndex
tmpItem1 = ListBox1.Items.Item(intIndex)
tmpItem2 = ListBox1.Items.Item(intIndex + 1)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.Insert(intIndex, tmpItem2)
ListBox1.Items.Insert(intIndex + 1, tmpItem1)
ListBox1.SelectedItem = ListBox1.Items.Item(intIndex + 1)
End If
End Sub
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"segue" <se***@discussions.microsoft.com> schreef in bericht
news:88**********************************@microsof t.com...

Hi;

I need to change the order of a listbox array from a form app
where I select order up or down.

What's a good way to do that?

Regards;

Segue


Nov 23 '05 #3
Please don't respond to this it's too complicated.

"segue" wrote:
Perfect. Thanks so much.

Another question.

I'm using a checkbox list (appname) that has fields associated
with each checkbox list appname. You click a button and I instantiate this
newform where you can choose the order of the fields. Then
I want to reinstantiate the newform with the next checkboxlist's
group of fields so that they can be ordered and then keep going for each
appname so I have a listbox that has a two dimensional array:
(1(appname1), field1)
(1(appname1), field1)
(1(appname1), field1)
(1(appname1), field1)
then appname2:
(1(appname2), field2)
(1(appname2), field2)
(1(appname2), field2)
(1(appname2), field2)

for the next appname and its group and so on.

Can anyone see a good design for this.
of fields and keep them in a listbox arraylist of appname1.

Regards;

Segue

"Peter Proost" wrote:
Hi try this, place two buttons and a listbox on a form, button1.text = UP,
button2.text = DOWN, the listbox should have selectionmode set to one. Now
you can try this code.

Hth Greetz Peter

Private Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
ListBox1.Items.Add("First")
ListBox1.Items.Add("Second")
ListBox1.Items.Add("Third")
ListBox1.Items.Add("Fourth")
ListBox1.Items.Add("Fifth")
ListBox1.Items.Add("Sixth")
ListBox1.Items.Add("Seventh")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Not ListBox1.SelectedItem Is Nothing Then
moveup()
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If Not ListBox1.SelectedItem Is Nothing Then
movedown()
End If
End Sub

Private Sub moveup()
Dim tmpItem1, tmpItem2 As Object
Dim intIndex As Integer
If ListBox1.SelectedIndex > 0 Then
intIndex = ListBox1.SelectedIndex
tmpItem1 = ListBox1.Items.Item(intIndex)
tmpItem2 = ListBox1.Items.Item(intIndex - 1)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.RemoveAt(intIndex - 1)
ListBox1.Items.Insert(intIndex - 1, tmpItem2)
ListBox1.Items.Insert(intIndex - 1, tmpItem1)
ListBox1.SelectedItem = ListBox1.Items.Item(intIndex - 1)
End If
End Sub

Private Sub movedown()
Dim tmpItem1, tmpItem2 As Object
Dim intIndex As Integer
If ListBox1.SelectedIndex < ListBox1.Items.Count - 1 Then
intIndex = ListBox1.SelectedIndex
tmpItem1 = ListBox1.Items.Item(intIndex)
tmpItem2 = ListBox1.Items.Item(intIndex + 1)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.Insert(intIndex, tmpItem2)
ListBox1.Items.Insert(intIndex + 1, tmpItem1)
ListBox1.SelectedItem = ListBox1.Items.Item(intIndex + 1)
End If
End Sub
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"segue" <se***@discussions.microsoft.com> schreef in bericht
news:88**********************************@microsof t.com...

Hi;

I need to change the order of a listbox array from a form app
where I select order up or down.

What's a good way to do that?

Regards;

Segue


Nov 23 '05 #4
So how do I get the reorganized listbox1 items back to my original main form?

"Peter Proost" wrote:
Hi try this, place two buttons and a listbox on a form, button1.text = UP,
button2.text = DOWN, the listbox should have selectionmode set to one. Now
you can try this code.

Hth Greetz Peter

Private Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
ListBox1.Items.Add("First")
ListBox1.Items.Add("Second")
ListBox1.Items.Add("Third")
ListBox1.Items.Add("Fourth")
ListBox1.Items.Add("Fifth")
ListBox1.Items.Add("Sixth")
ListBox1.Items.Add("Seventh")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Not ListBox1.SelectedItem Is Nothing Then
moveup()
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If Not ListBox1.SelectedItem Is Nothing Then
movedown()
End If
End Sub

Private Sub moveup()
Dim tmpItem1, tmpItem2 As Object
Dim intIndex As Integer
If ListBox1.SelectedIndex > 0 Then
intIndex = ListBox1.SelectedIndex
tmpItem1 = ListBox1.Items.Item(intIndex)
tmpItem2 = ListBox1.Items.Item(intIndex - 1)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.RemoveAt(intIndex - 1)
ListBox1.Items.Insert(intIndex - 1, tmpItem2)
ListBox1.Items.Insert(intIndex - 1, tmpItem1)
ListBox1.SelectedItem = ListBox1.Items.Item(intIndex - 1)
End If
End Sub

Private Sub movedown()
Dim tmpItem1, tmpItem2 As Object
Dim intIndex As Integer
If ListBox1.SelectedIndex < ListBox1.Items.Count - 1 Then
intIndex = ListBox1.SelectedIndex
tmpItem1 = ListBox1.Items.Item(intIndex)
tmpItem2 = ListBox1.Items.Item(intIndex + 1)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.Insert(intIndex, tmpItem2)
ListBox1.Items.Insert(intIndex + 1, tmpItem1)
ListBox1.SelectedItem = ListBox1.Items.Item(intIndex + 1)
End If
End Sub
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"segue" <se***@discussions.microsoft.com> schreef in bericht
news:88**********************************@microsof t.com...

Hi;

I need to change the order of a listbox array from a form app
where I select order up or down.

What's a good way to do that?

Regards;

Segue


Nov 23 '05 #5
By using a property or a reference

Greetz Peter
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"segue" <se***@discussions.microsoft.com> schreef in bericht
news:5B**********************************@microsof t.com...
So how do I get the reorganized listbox1 items back to my original main form?
"Peter Proost" wrote:
Hi try this, place two buttons and a listbox on a form, button1.text = UP, button2.text = DOWN, the listbox should have selectionmode set to one. Now you can try this code.

Hth Greetz Peter

Private Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox1.Items.Add("First")
ListBox1.Items.Add("Second")
ListBox1.Items.Add("Third")
ListBox1.Items.Add("Fourth")
ListBox1.Items.Add("Fifth")
ListBox1.Items.Add("Sixth")
ListBox1.Items.Add("Seventh")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Not ListBox1.SelectedItem Is Nothing Then
moveup()
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If Not ListBox1.SelectedItem Is Nothing Then
movedown()
End If
End Sub

Private Sub moveup()
Dim tmpItem1, tmpItem2 As Object
Dim intIndex As Integer
If ListBox1.SelectedIndex > 0 Then
intIndex = ListBox1.SelectedIndex
tmpItem1 = ListBox1.Items.Item(intIndex)
tmpItem2 = ListBox1.Items.Item(intIndex - 1)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.RemoveAt(intIndex - 1)
ListBox1.Items.Insert(intIndex - 1, tmpItem2)
ListBox1.Items.Insert(intIndex - 1, tmpItem1)
ListBox1.SelectedItem = ListBox1.Items.Item(intIndex - 1)
End If
End Sub

Private Sub movedown()
Dim tmpItem1, tmpItem2 As Object
Dim intIndex As Integer
If ListBox1.SelectedIndex < ListBox1.Items.Count - 1 Then
intIndex = ListBox1.SelectedIndex
tmpItem1 = ListBox1.Items.Item(intIndex)
tmpItem2 = ListBox1.Items.Item(intIndex + 1)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.Insert(intIndex, tmpItem2)
ListBox1.Items.Insert(intIndex + 1, tmpItem1)
ListBox1.SelectedItem = ListBox1.Items.Item(intIndex + 1)
End If
End Sub
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"segue" <se***@discussions.microsoft.com> schreef in bericht
news:88**********************************@microsof t.com...

Hi;

I need to change the order of a listbox array from a form app
where I select order up or down.

What's a good way to do that?

Regards;

Segue


Nov 23 '05 #6
I had to save the re-ordered listbox back to the orignal form in
a file. If I did it as a property it didn't seem like I could save it back
to the original forms listbox.

Regards;

Segue

"Peter Proost" wrote:
By using a property or a reference

Greetz Peter
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"segue" <se***@discussions.microsoft.com> schreef in bericht
news:5B**********************************@microsof t.com...
So how do I get the reorganized listbox1 items back to my original main

form?

"Peter Proost" wrote:
Hi try this, place two buttons and a listbox on a form, button1.text = UP, button2.text = DOWN, the listbox should have selectionmode set to one. Now you can try this code.

Hth Greetz Peter

Private Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox1.Items.Add("First")
ListBox1.Items.Add("Second")
ListBox1.Items.Add("Third")
ListBox1.Items.Add("Fourth")
ListBox1.Items.Add("Fifth")
ListBox1.Items.Add("Sixth")
ListBox1.Items.Add("Seventh")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Not ListBox1.SelectedItem Is Nothing Then
moveup()
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If Not ListBox1.SelectedItem Is Nothing Then
movedown()
End If
End Sub

Private Sub moveup()
Dim tmpItem1, tmpItem2 As Object
Dim intIndex As Integer
If ListBox1.SelectedIndex > 0 Then
intIndex = ListBox1.SelectedIndex
tmpItem1 = ListBox1.Items.Item(intIndex)
tmpItem2 = ListBox1.Items.Item(intIndex - 1)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.RemoveAt(intIndex - 1)
ListBox1.Items.Insert(intIndex - 1, tmpItem2)
ListBox1.Items.Insert(intIndex - 1, tmpItem1)
ListBox1.SelectedItem = ListBox1.Items.Item(intIndex - 1)
End If
End Sub

Private Sub movedown()
Dim tmpItem1, tmpItem2 As Object
Dim intIndex As Integer
If ListBox1.SelectedIndex < ListBox1.Items.Count - 1 Then
intIndex = ListBox1.SelectedIndex
tmpItem1 = ListBox1.Items.Item(intIndex)
tmpItem2 = ListBox1.Items.Item(intIndex + 1)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.RemoveAt(intIndex)
ListBox1.Items.Insert(intIndex, tmpItem2)
ListBox1.Items.Insert(intIndex + 1, tmpItem1)
ListBox1.SelectedItem = ListBox1.Items.Item(intIndex + 1)
End If
End Sub
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"segue" <se***@discussions.microsoft.com> schreef in bericht
news:88**********************************@microsof t.com...
>
> Hi;
>
> I need to change the order of a listbox array from a form app
> where I select order up or down.
>
> What's a good way to do that?
>
> Regards;
>
> Segue


Dec 11 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: VikingHun | last post by:
Hi all;) I recently thought about making a program that would output all possible orders that groups of numbers, characters etc. of different sizes could have.(eg. 1,2,3 1,3,2 2,1,3 2,3,1 ...
1
by: nm | last post by:
How can I change the order of DataGrid columns? I have a Master-Detail relationship and the columns in the datagrid look like they are lined up in alphabetical order which is not what I want.
1
by: Greg Teets | last post by:
Is there an easy way to do this, like a button to move a higlighted column up or down in the table desctiption? Do I need to make a new table or is there an easier way? Thanks. Greg Teets...
4
by: Wally | last post by:
This is probably a very simple problem, but I can't figure out the coding for it. I have a list box that displays one of my tables. I'd the user to be able to reorder the items in the list box...
3
by: Bruce HS | last post by:
When I raise an event in an ancestor, the event fires first in the ancestor, then its descendant, and then in the descendant's descendant. I would like the descendant's descendant to fire first...
4
by: Stephen | last post by:
Hi, How do i let a user change the order of some parameters on a web page? suppose by default when the web page is loaded, suppose he sees this like on a grid PK Rule 1 Rule 1 2 ...
13
by: Kevin | last post by:
Hi, I have used ASP for years using MS Access and have used MSSQL quite a lot as well. I have never came across something like this before. MSSQL table names and types: ProductName nvarchar...
1
by: technod | last post by:
Hi, I have constructed a clickable list of words which are added to a select box. I then have buttons to move the added elements up or down in the list. The code below seems to work fine for...
5
by: marton | last post by:
Hi there, I'm new to posting on the forum, and I've been working with MS Access for a couple of years, but and other than that know nothing about programming. I have a fairly simple, networked,...
2
by: cmartin1986 | last post by:
Hi all, I have a stacked column chart built in access and it automatically sorts by alpha order I need it in a certain order that isnt alphabetical and i was wondering how i could go about doing...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.