My listview has 3 columns. "Text" , "Delay" and "".
The "" column is to show which one is being ran by filling it with a "<".

If I use
List.Items(currentTimer - 1).SubItems.Add("<")
Then it works, but how will I remove it?
SubItems(1) modifies column 1, and SubItems(2) is out of range.

Thanks in advance.

Recommended Answers

All 11 Replies

ListViewItems are zero based.

Therefore 0 will be column one, and 1 will be column two.

Sorry, I meant that.
0 = Column 1
1 = Column 2
2 = Out of range (Its suppost to be column 3)

did you already inserted an item to other coulumns?
I guess List.Items(currentTimer - 1).SubItems.Add("<") were added to column1.. only a guess :)

List.Items(currentTimer - 1).SubItems.Add("<") adds < to column 3.
I'm pretty sure thats only because column 1 and 2 are filled.

Just to clear this up a little bit:

SubItems(1) modifies column 2.
SubItems(2) is out of range. (It is suppost to be column 3.)
Items(int) modifies the first column.

There is obviously something wrong here.

Edit: In Microsoft Visual Studio, the properties for ListView, does "TabIndex" have something to do with this?
It's currently set to 0.

Can you please post the block of code that is throwing the error?

Seeing the code would help bring a better understanding of your problem.

 List.Items(currentTimer - 1).SubItems(List.Items(currentTimer - 1).SubItems.Count).Text = ""

Here is a peice of code that I expect to work.
But, there is an error.
"Value of '2' is not valid for 'index' "

Which index is it complaining about? You have two

  • currentTimer - 1
  • List.Items(currentTimer - 1).SubItems.Count

Try replacing the code with

Debug.WriteLine("index 1 = " & (CurrentTimes - 1).ToString)
Debug.WriteLine("index 2 = " & (List.Items(currentTimer - 1).SubItems.Count).ToString)
Debug.WriteLine("# items = " & List.Items.Count)
List.Items(currentTimer - 1).SubItems(List.Items(currentTimer - 1).SubItems.Count).Text = ""

The obvious problem is that you are either indexing past the number of items or past the number of subitems. You can't determine that just by looking at the code. You have to see the actual values of the indices.

The problem is in the second index, List.Items(currentTimer - 1).SubItems.Count .

My program waits the amount of time in column 2 (it has to be a double)
and then it prints what is in column 1. In column 3, there is suppost to be "<" indicating what it is waiting for.

List.Items(currentTimer - 1).SubItems(List.Items(currentTimer - 1).SubItems.Count).Text = ""

Will probably not work because Count will always return a number whic is one more than the highest valid index. Iitems and SubItems are zero-relative indexed so if you have 5 SubItems then then Count = 5 and the rightmost SubIitem has an index of 4.

commented: Sorry for absence. +8

As Jim has stated, listviews are zero based.


List.Items(currentTimer - 1).SubItems(List.Items(currentTimer - 1).SubItems.Count).Text = ""

Should be:

List.Items(currentTimer - 1).SubItems(List.Items(currentTimer - 1).SubItems.Count - 1).Text = ""
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.