473,662 Members | 2,631 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Selecte dIndexChanged procedure began as follows:

NextPointID = ListBox_Points. SelectedIndex + 1

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

NextPointID = ListView_Points .SelectedIndice s(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.Argumen tOutOfRangeExce ption'
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 1540
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.Selecte dIndexChanged procedure began as follows:

NextPointID = ListBox_Points. SelectedIndex + 1

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

NextPointID = ListView_Points .SelectedIndice s(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.Argumen tOutOfRangeExce ption'
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**@technetce nter.com> wrote in
news:v8******** ***********@big news5.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.Selecte dIndexChanged procedure began as follows:

NextPointID = ListBox_Points. SelectedIndex + 1

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

NextPointID = ListView_Points .SelectedIndice s(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.Argumen tOutOfRangeExce ption'
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 SelectedIndexCh anged:

if listbox_points. selectedindices .count = 0 then return

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

Jan 13 '06 #4
"Armin Zingler" <az*******@free net.de> wrote in news:O75zwxGGGH A.2300
@TK2MSFTNGP15.p hx.gbl:
Add this as the first line in SelectedIndexCh anged:

if listbox_points. selectedindices .count = 0 then return

Reason: If you select another item, the previous item is un-selected and
SelectedIndexCh anged 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 SelectedIndexCh anged
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
1757
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 so that I have the icon + the string in a listbox. Is this possible, and if so, can you give me some idea how to go about it. Thanks for any help. Bernie Yaeger
1
1478
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) { //....... base.OnClick(e); }
2
8620
by: Kanaiya | last post by:
hello how to put images in either listbox or listview.bye. -- With regards, Gangani Kanaiya.
3
10265
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 over when the right click occurred. Is this possible? Thanks, Cristov
2
23353
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 show up for each item I add to the listbox. foreach (Column column in columns) { ColumnsListBox.Items.Add(column.Name); ColumnsListBox.Controls.Add(new ColumnListControl(true, column.Name,
2
5737
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 make multiple selections. The problem I am having is that when I use the shift key to select a range of items, I first click on one item (item gets highlighted), then, holding down the shift key, I select another item (the range of items gets...
3
3297
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 items. I tried setting up an array to capture the selected items and then move them with the dragndrop code, but after selecting the items when the user clicks on the items to drag them the selection goes back to one item. Also I have code for the...
1
7710
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: " & Point(T).Latitude...) Next I end up with data in the following format in each ListBox line. 1 Lat: 42.5003, Long: -70.9249, Ele 161
2
10642
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 the listbox entry with the corresponding DataRow. The DataRow contains a unique id, but the id is not displayed in the formatted string that appears in the listbox. Is there a way to associate the id of the DataRow with the Listbox item so I...
0
8435
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8345
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8768
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8547
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5655
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4181
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.