473,397 Members | 2,056 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,397 software developers and data experts.

Migrating From ListBox to ListView: Only One Problem

I've nearly completed the migration of my first ListBox control to a
ListView in detail view, and I'm only experiencing one problem:

My ListBox.SelectedIndexChanged procedure began as follows:

NextPointID = ListBox_Points.SelectedIndex + 1

The equivalent of that command for a ListView would seem to be:

NextPointID = ListView_Points.SelectedIndices(0) + 1

Since my ListView doesn't allow multiselect, the first (0th) SelectedIndex
in the collection would always be the only member, correct?

A single execution of that line of code works perfectly, but if I attempt
to choose another index, it returns the following error:

---

An unhandled exception of type 'System.ArgumentOutOfRangeException'
occurred in system.windows.forms.dll

Additional information: Specified argument was out of the range of valid
values.

---

So, what's the sitch? What'd I do wrong?

Thanks in advance for any assistance,

The Confessor
Jan 13 '06 #1
4 1521
You said the answer yourself - you don't allow multi-select, so you
can't use a different index.

Tom

The Confessor wrote:
I've nearly completed the migration of my first ListBox control to a
ListView in detail view, and I'm only experiencing one problem:

My ListBox.SelectedIndexChanged procedure began as follows:

NextPointID = ListBox_Points.SelectedIndex + 1

The equivalent of that command for a ListView would seem to be:

NextPointID = ListView_Points.SelectedIndices(0) + 1

Since my ListView doesn't allow multiselect, the first (0th) SelectedIndex
in the collection would always be the only member, correct?

A single execution of that line of code works perfectly, but if I attempt
to choose another index, it returns the following error:

---

An unhandled exception of type 'System.ArgumentOutOfRangeException'
occurred in system.windows.forms.dll

Additional information: Specified argument was out of the range of valid
values.

---

So, what's the sitch? What'd I do wrong?

Thanks in advance for any assistance,

The Confessor

Jan 13 '06 #2
tomb <to**@technetcenter.com> wrote in
news:v8*******************@bignews5.bellsouth.net:
You said the answer yourself - you don't allow multi-select, so you
can't use a different index.

Tom


Are you certain you understood the question I was asking? I've
intentionally set MultiSelect to false.

What I want is a way to pass the index of the sole selected item + 1 to the
NextPointID variable.

My current code will do this only once, crashing *on that line* on the
second iteration.
Jan 13 '06 #3
"The Confessor" <in*****@reply.to.group> schrieb
I've nearly completed the migration of my first ListBox control to a
ListView in detail view, and I'm only experiencing one problem:

My ListBox.SelectedIndexChanged procedure began as follows:

NextPointID = ListBox_Points.SelectedIndex + 1

The equivalent of that command for a ListView would seem to be:

NextPointID = ListView_Points.SelectedIndices(0) + 1

Since my ListView doesn't allow multiselect, the first (0th)
SelectedIndex in the collection would always be the only member,
correct?

A single execution of that line of code works perfectly, but if I
attempt to choose another index, it returns the following error:

---

An unhandled exception of type 'System.ArgumentOutOfRangeException'
occurred in system.windows.forms.dll

Additional information: Specified argument was out of the range of
valid values.

---

So, what's the sitch? What'd I do wrong?

Add this as the first line in SelectedIndexChanged:

if listbox_points.selectedindices.count = 0 then return

Reason: If you select another item, the previous item is un-selected and
SelectedIndexChanged is raised. Count = 0 in this case.
Armin

Jan 13 '06 #4
"Armin Zingler" <az*******@freenet.de> wrote in news:O75zwxGGGHA.2300
@TK2MSFTNGP15.phx.gbl:
Add this as the first line in SelectedIndexChanged:

if listbox_points.selectedindices.count = 0 then return

Reason: If you select another item, the previous item is un-selected and
SelectedIndexChanged is raised. Count = 0 in this case.
Armin


!

Took me a few minutes to see what you were saying:

Whereas selecting a different ListBox entry raises the SelectedIndexChanged
event only once, selecting a different ListView entry raises it twice. Once
for the de-selection of the previous index, and one for the selection of
the new.

This requires a bail-out statement in case of the former prior to any tests
of SelectedIndice content.

A hellishly devious change.

I am in your debt, Armin.

The Confessor
Jan 13 '06 #5

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

Similar topics

4
by: Bernie Yaeger | last post by:
I now know how to gather the file type icons and I'm able to use them in a listview. But a listbox does not have a .smallimagelist or .largeimagelist member, so I don't know how to translate that...
1
by: David | last post by:
Hi ListBox, ListView and other controls have inherited methods and properties. I could not understand how to use them. For example if I have protected override void OnClick( System.EventArgs e)...
2
by: Kanaiya | last post by:
hello how to put images in either listbox or listview.bye. -- With regards, Gangani Kanaiya.
3
by: Chris | last post by:
I'm able to add a context menu to the right click on a listbox but it does not select the item in the listbox. I would like the context menu before it pops up to select the item that the mouse was...
2
by: John R. | last post by:
I want to have a listbox that shows a checkbox and a textbox. I created a user control that has a checkbox and a textbox in it and have been trying to add it to a listbox but I can't get it to...
2
by: Matt Sawyer | last post by:
Hi, I'm attempting to do a drag and drop operation from one listbox to another. I have my listboxes setup with SelectionMode = MultiExtended so that I can use the shift key, cntrl key, etc. to...
3
by: thomasp | last post by:
Has anyone got some sample code to do drag and drop from one listbox to another listbox using VB.Net 2005. The below code works for draging and droping one at a time, but not for multiselected...
1
by: The Confessor | last post by:
I currently have a listbox in my program which I populate with data from a random access file as follows: For T = 1 To HighestPointID FileGet(1, Point(T), T) ListBox_Point.Items.Add(T & " Lat:...
2
by: markliam | last post by:
I have a ListBox that is displaying a formatted string based on the contents of a DataSet. The purpose of the listbox is for the user to select an entry to delete, but I'm not sure how to match...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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...

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.