Reapz Posted November 17, 2003 Posted November 17, 2003 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? Quote I'm getting the hang of this now... No really I am!
Administrators PlausiblyDamp Posted November 17, 2003 Administrators Posted November 17, 2003 Any chance you could post some code? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Reapz Posted November 17, 2003 Author Posted November 17, 2003 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. Quote I'm getting the hang of this now... No really I am!
Administrators PlausiblyDamp Posted November 17, 2003 Administrators Posted November 17, 2003 How are you creating the list view? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
*Experts* Volte Posted November 17, 2003 *Experts* Posted November 17, 2003 Looks like you don't have enough listview headers in your listview. Are there 8? Quote
Reapz Posted November 18, 2003 Author Posted November 18, 2003 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. Quote I'm getting the hang of this now... No really I am!
pendragon Posted November 18, 2003 Posted November 18, 2003 (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 November 18, 2003 by pendragon Quote
Reapz Posted November 19, 2003 Author Posted November 19, 2003 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. Quote I'm getting the hang of this now... No really I am!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.