0

ok, on a button click how could i have the listview selected item jump to the next. so if there was a list view with 3 items and the second was selected. On a button clickhow could i make it jump to the third?

-T

2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by tayspen
Featured Replies
  • [code] int current = this.listView1.SelectedIndices[0]; int next = current == this.listView1.Items.Count - 1 ? 0 : current + 1; this.listView1.Focus(); this.listView1.Items[next].Selected = true; this.listView1.Items[current].Selected = false; [/code] note: this will jump back to the first one when the last one was selected Read More

1
int current = this.listView1.SelectedIndices[0];
int next = current == this.listView1.Items.Count - 1 ? 0 : current + 1;
this.listView1.Focus();
this.listView1.Items[next].Selected = true;
this.listView1.Items[current].Selected = false;

note: this will jump back to the first one when the last one was selected

Comments
Thanks, very helpful
0
int current = this.listView1.SelectedIndices[0];
int next = current == this.listView1.Items.Count - 1 ? 0 : current + 1;
this.listView1.Focus();
this.listView1.Items[next].Selected = true;
this.listView1.Items[current].Selected = false;

note: this will jump back to the first one when the last one was selected

thanks that worked. And to make it go the other way is a very simple tweak :)
Thanks again

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.