Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Got a listview on my form that originally had 6 subitems for each item. I have recently increased that number to 8.

 

I am trying to fill and reference those two new subitems with exactly the same code that I am using for the others but with different values, so I know the code is ok. However, i keep getting an 'out of range of specified values' error which to me implies that the two extra columns are missing.

 

I tried recreating the the listview from scratch but still no good. I have also checked the forms designer code and that is correct too.

 

Is there a limit to the number of subitems or could this be a bug?

I'm getting the hang of this now... No really I am!
Posted

Sure but it's pretty simple stuff....

 

(lvi is declared publicly as a ListViewItem and all the following bits of code are inside for... next loops.)

 

This simplest example is when i reset the values...

 

lvi.SubItems(1).Text = "" 'WORKS
lvi.SubItems(2).Text = "" 'WORKS
lvi.SubItems(3).Text = TimePlayed + TotalTime 'WORKS
lvi.SubItems(4).Text = TotalCTTime + CTTime 'WORKS
lvi.SubItems(5).Text = TotalTTime + TTime 'WORKS
lvi.SubItems(6).Text = "" 'WORKS
lvi.SubItems(7).Text = "" 'GIVES THE ERROR
lvi.SubItems(8).Text = "" 'GIVES THE ERROR

 

Or if I try and retrieve the values...

 

If oldteam = "CT" Then
    Dim TeamTime As TimeSpan = Leftgame.Subtract(Entered)
    Dim TotalCTTime = Val(lvi.SubItems(4).Text)
    CTTime = TeamTime.TotalMinutes
    lvi.SubItems(4).Text = CTTime + TotalCTTime
ElseIf oldteam = "TERRORIST" Then
    Dim TeamTime As TimeSpan = Leftgame.Subtract(Entered)
    Dim TotalTTime = Val(lvi.SubItems(5).Text)
    TTime = TeamTime.TotalMinutes
    lvi.SubItems(5).Text = TTime + TotalTTime
End If

'WORKS FINE

If lvi.Text = parts(1) Then
    Dim CurrentKills = Val(lvi.SubItems(7).Text)
    lvi.SubItems(7).Text = CurrentKills + 1
ElseIf lvi.Text = VParts(1) Then
    Dim CurrentDeaths = Val(lvi.SubItems(8).Text)
    lvi.SubItems(8).Text = CurrentDeaths + 1
End If

'GIVES THE ERROR

 

Like I said... Simple stuff and I can't see why, particularly in the first example, why it would work for subitems 1 - 6 but not 7 & 8.

I'm getting the hang of this now... No really I am!
Posted

I didn't code the ListView, I just added it to the form. At first it only had 7 columns (item & 6 subitems) and then I added 2 more.

 

I have since removed the old one and redone just to see if that made any difference but it didn't.

 

I have checked the form designer code and all the column headers are in there. It just won't acknowledge columns 7 & 8 when I try to do anything with them.

I'm getting the hang of this now... No really I am!
Posted (edited)

I have managed to re-produced the error you are getting

 

If you setup the list view with the ListViewItems collection editor/ListViewSubItems collection editor and only have the main item and six items defined, SubItem(7) and SubItem(8) will not work even if you have those columns set up.

 

Don't know if that is how you set it up or if you are coding it somewhere.

 

To fix either add two more items to the subitem collection or use SubItems.Add(7).

Edited by pendragon
Posted

Ok... more weirdness...

 

I added 5 extra column headers and 5 extra subitems that didn't serve any purpose and all of a sudden I could access 7 & 8.

 

I've since deleted the superfluous headers and subitems and its still works!

 

Very strange...

 

Cheers guys.

I'm getting the hang of this now... No really I am!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...