PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
Migrating From ListBox to ListView: Only One Problem
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
Migrating From ListBox to ListView: Only One Problem
![]() |
Migrating From ListBox to ListView: Only One Problem |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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 > > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
tomb <tomb@technetcenter.com> wrote in
news:v8Qxf.37244$qw4.12007@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. |
|
|
|
#4 |
|
Guest
Posts: n/a
|
"The Confessor" <invalid@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 |
|
|
|
#5 |
|
Guest
Posts: n/a
|
"Armin Zingler" <az.nospam@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 |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

