المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : timers in listview [modified]



C# Programming
06-04-2009, 02:50 PM
hey i am working in .net application in c#.........i need to delete differnt items from list view with the help of timer on the selectedindexchange event.....the problem is that when i select one item at a time within the elapsing time of the timer there is no problem, but when i select multiple items at a time within the elapsing time of the timer the timer is set only on the last selected item and it gets removed from the previous one............is there any way to set timer on every selected item of the listview.......i need the code in c#......kindly help....
this is what i am doin........

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace timer
{
public partial class Form2 : Form
{
System.Windows.Forms.Timer m_Timer;

public Form2()
{
InitializeComponent();
listView1.SmallImageList = AlertImageList;
m_Timer = new Timer();
m_Timer.Interval = 5000;
m_Timer.Tick += new EventHandler(m_Timer_Tick);

}

void m_Timer_Tick(object sender, EventArgs e)
{
listView1.Items.RemoveAt(y);

}

public int y;

private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (listView1.Items.Count > 0)
{
y = listView1.SelectedItems[0].Index;
//m_Timer.Stop();
m_Timer.Start();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

public int i = 0;

private void btnClick_Click(object sender, EventArgs e)
{
ListViewItem item = new ListViewItem(i.ToString());
listView1.Items.Insert(0, item);
i++;
}

}
}

modified on Thursday, June 4, 2009 6:32 AM