Click here to Skip to main content
15,886,873 members

List view Selection one by one

vasanthkumarmk asked:

Open original thread
Hai to all,

I have done one task but it is not proper, just you guys fine tune my task.

I am using Windows Application with C# Languvage.

I have one Listview (Listview contain 5 Items), 2 Buttons (Play, Pause)

Aim : My goal is when I click the Play Button the listview top first item will select and the selection will moves one by one of some particular timing interval.

I have done: What I have done is, Listview item will select using forloop, it will moves one by one for particular timing interval using thread.sleep(3000) method , and the same time, From listview selection change event I have to select that particular item.

Error :
1. But when I start Play Button listview items will select and moves one by one, But I am using messagebox (See coding below) in listview selection change event, For that only it will select one by one, Without messagebox it won't select one by one.

(I need without using messagebox it will select one by one)

2. Secondly, When I Click the Pause Button the process won't stop. It is continuous running.

(I need to Stop the process when I click the pause Button)


My Coding:

------------------------------- Coding Starts --------------------------------------
// Play Button Click Event

C#
private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0, j = 0; i < listView1.Items.Count && j < listView1.Items.Count; j++)
            {
                if (j != 0)
                {
                    listView1.Items[j - 1].Selected = false;
                }

                listView1.Items[j].Selected = true;                            

                Thread.Sleep(3000);

                if (j == listView1.Items.Count - 1)
                {
                    listView1.Items[j].Selected = false;                    
                    j = -1;

                }
               
            }
        }


//List view Selection index Change coding

C#
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {              
                listView1.Select();
                MessageBox.Show(listView1.SelectedIndices[0].ToString());
            }
        }



//Pause Button Click Event

C#
private void button2_Click(object sender, EventArgs e)
        {
             //I Don't Know what coding write to Stop that process.

        }


--------------------------- Coding Finished ---------------------------

I Hope Every one Understand what I am asking, If any one not able to understood i am ready to explain once again. But I need the Solution.

Regards,
Vasanth
Tags: C# (C# 2.0, C# 3.0, C# 4.0)

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900