This timer tick code is used to monitor users in the listview according to there last login time.
Step 1: In visual studio choose windows application and take listview control in the toolbox and Insert a Dummy datetime for a user in the listview.
Step 2: Take timer component in toolbox in visual studio.
Step 3: Double click the timer component and automatically timer tick method will generate.
Step 4: Write this code inside the timer tick method.
private void timer1_Tick_2(object sender, EventArgs e)
foreach (ListViewItem itm in MemberslistView.Items)
for (int i = 0; i < MemberslistView.Items.Count; i++)
DateTime last = DateTime.Parse(itm.SubItems.Text);
DateTime now = DateTime.Now;
TimeSpan ts = now – last;
string time = ts.ToString();
TimeIn = time.Substring(0, time.Length – 8); //Trimming the nano seconds
itm.SubItems.Text = TimeIn.ToString();
Listview is the class and members listview is the listview control ID name.To run the timer tick for subitem in the listview we need to take position of that subitem.Here the dummy datetime position is 1 according to there index and we need to see the result in another subitem which is index 0..Last logging time is going to compare with present datetime class object and getting the difference into timespan class object.Converting datetime into string using timespan class object and updating the result into subitem index 0. Memberlistview.items.count will count the total number of rows in the listview.