472,780 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 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 7120
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.