11 Replies - 4222 Views - Last Post: 10 October 2012 - 10:30 PM Rate Topic: -----

#1 jhedonghae  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

adding items to listview

Posted 10 October 2012 - 05:04 AM

can anyone help me in adding items to a listview?
here is what i want to do: when i click the login button the date and time will be added in the column date and time in, here is my code and it worksClick Here:

Private Sub LoginButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginButton.Click
    For Each item As ListViewItem In TimeSheetListView.Items
        Select Case True
            Case item.SubItems(0).Text = dates.Text
                Return
            Case item.SubItems(1).Text = time.Text
                Return
        End Select
    Next
    Dim lv As ListViewItem = TimeSheetListView.Items.Add(dates.Text)
    lv.SubItems.Add(time.Text)
    lv.SubItems.Add(time.Text)
    If TimeSheetListView.Items.Count >= 1 Then
        MsgBox("You are logged in.", MsgBoxStyle.Information, "Message")
        LoginButton.Enabled = False
        LogoutButton.Enabled = True
    End If
End Sub

my problem is the log out button, i want to add the time, in the time out column but i dont know how
i had attach a printscreen of my work..hope anyone can help

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: adding items to listview

#2 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: adding items to listview

Posted 10 October 2012 - 06:27 AM

What are dates.Text and times.Text?

It looks like you are trying to disallow a login if there is one already there on the same date and/or time. Is that correct?

It looks like you already know how to add date and time at login. What is preventing you from doing it for logout? Is there a particular problem that's stopping you? Can you show us code you've tried?
Was This Post Helpful? 0
  • +
  • -

#3 jhedonghae  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Re: adding items to listview

Posted 10 October 2012 - 06:55 AM

View Postlar3ry, on 10 October 2012 - 06:27 AM, said:

What are dates.Text and times.Text?

It looks like you are trying to disallow a login if there is one already there on the same date and/or time. Is that correct?

It looks like you already know how to add date and time at login. What is preventing you from doing it for logout? Is there a particular problem that's stopping you? Can you show us code you've tried?


yes i already know how to add date and time at login..
in the log out button i have tried the same code but it doesn't add items in the column time out
Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: adding items to listview

Posted 10 October 2012 - 07:03 AM

The same code won't work because you are returning if date and time is filled in and it is
You're going to have to determine what line you want to put clockout into and set subitem(2) = to the clockout time.
Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: adding items to listview

Posted 10 October 2012 - 07:11 AM

You're going to have a lot of headaches with this the way you're going.

For example, have you thought about how to let someone clockout for lunch that forgot to clockin when they came in to work?

Employees will screw this up and when they do, it will require some ability to fix these situations or you will have difficulty getting everything correct in the course of a day

A better method would be to set a ClockType (ClockIN, ClockOUT) and record at timestamp (date and time)

So the user want's to clockin, you record the user, the datetime and the type

This lets the user notify of a "forgotten clockin or clockout" and still lets them use the timeclock.

Then when you're calculating total times, you will have to check to determine if the record is missing any entries to be complete. (ie, ClockIN, ClockIN, ClockOut) = missing a clockout somewhere

I'm not sure there is any "Headache-Free" sure fire way when it comes to timeclocks since it depends on an employee using it properly.
Was This Post Helpful? 0
  • +
  • -

#6 jhedonghae  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Re: adding items to listview

Posted 10 October 2012 - 07:41 AM

View PostCharlieMay, on 10 October 2012 - 07:11 AM, said:

You're going to have a lot of headaches with this the way you're going.

For example, have you thought about how to let someone clockout for lunch that forgot to clockin when they came in to work?

Employees will screw this up and when they do, it will require some ability to fix these situations or you will have difficulty getting everything correct in the course of a day

A better method would be to set a ClockType (ClockIN, ClockOUT) and record at timestamp (date and time)

So the user want's to clockin, you record the user, the datetime and the type

This lets the user notify of a "forgotten clockin or clockout" and still lets them use the timeclock.

Then when you're calculating total times, you will have to check to determine if the record is missing any entries to be complete. (ie, ClockIN, ClockIN, ClockOut) = missing a clockout somewhere

I'm not sure there is any "Headache-Free" sure fire way when it comes to timeclocks since it depends on an employee using it properly.

did i get your idea right? i had attach an image based on what i had understand..BTW thanks for the idea

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#7 jhedonghae  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Re: adding items to listview

Posted 10 October 2012 - 07:51 AM

but i'm still having a problem on how to add the clockout to the subitem(2) using the logout button
Was This Post Helpful? 0
  • +
  • -

#8 jhedonghae  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Re: adding items to listview

Posted 10 October 2012 - 07:59 AM

is it possible to add the date in subitem(0) and clockin in subitem(1) using the login button and add the clockout in subitem(2) using the logout button?
Was This Post Helpful? 0
  • +
  • -

#9 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: adding items to listview

Posted 10 October 2012 - 08:05 AM

Is that because you don't know how to ensure you're writing to the correct entry or you don't know how to set it?

In a perfect clockin clockout world, a clockout should be the last thing to occur in the list. So if you had 3 entries in your list (index 0 to 2) then you would want to update index 2 since every other clockin and clockout should have occurred properly (remember, we're talking a perfect world here)

That being the case. A clockout should go into the index of (listview1.items.Count -1)

So you could use
TimeSheetListView.Items(TimeSheetListView.Items.Count-1).SubItems(2).Text = {your clockout time}


This will always find the last entry and set the clockout to the time you specify.

Again, in a no-so-perfect world, can you see the ramifications of trying to manipulate time entries in this fashion.

IF someone did indeed forget to clock in after lunch, but wanted to clockout to go home, their previous clockout will be changed to this time because it's the last in the list. This is why I stated that you need to figure out HOW to determine which row you are wanting to change.

Example Bill clocks in for work and then clocks out to go to lunch. The entry in the list is
DATE         | Clock IN  |  Clock OUT |
10/10/2012   | 7:00 AM   |  12:00 PM  |

Now Bill returns from lunch but forgets to clock back in so no new entries are entered.

When it's time to go home at 4:00 PM, Bill needs to clockout so he clicks Clock Out on the time
clock. Your list will now look like this
DATE         | Clock IN  |  Clock OUT |
10/10/2012   | 7:00 AM   |  4:00 PM  |


Because Bill didn't do this properly, your software changed his entry because it based everything off a perfect scenario. There are no perfect scenario's when Users are involved.
Was This Post Helpful? 0
  • +
  • -

#10 jhedonghae  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Re: adding items to listview

Posted 10 October 2012 - 08:17 AM

View PostCharlieMay, on 10 October 2012 - 08:05 AM, said:

Is that because you don't know how to ensure you're writing to the correct entry or you don't know how to set it?

In a perfect clockin clockout world, a clockout should be the last thing to occur in the list. So if you had 3 entries in your list (index 0 to 2) then you would want to update index 2 since every other clockin and clockout should have occurred properly (remember, we're talking a perfect world here)

That being the case. A clockout should go into the index of (listview1.items.Count -1)

So you could use
TimeSheetListView.Items(TimeSheetListView.Items.Count-1).SubItems(2).Text = {your clockout time}


This will always find the last entry and set the clockout to the time you specify.

Again, in a no-so-perfect world, can you see the ramifications of trying to manipulate time entries in this fashion.

IF someone did indeed forget to clock in after lunch, but wanted to clockout to go home, their previous clockout will be changed to this time because it's the last in the list. This is why I stated that you need to figure out HOW to determine which row you are wanting to change.

Example Bill clocks in for work and then clocks out to go to lunch. The entry in the list is
DATE         | Clock IN  |  Clock OUT |
10/10/2012   | 7:00 AM   |  12:00 PM  |

Now Bill returns from lunch but forgets to clock back in so no new entries are entered.

When it's time to go home at 4:00 PM, Bill needs to clockout so he clicks Clock Out on the time
clock. Your list will now look like this
DATE         | Clock IN  |  Clock OUT |
10/10/2012   | 7:00 AM   |  4:00 PM  |


Because Bill didn't do this properly, your software changed his entry because it based everything off a perfect scenario. There are no perfect scenario's when Users are involved.


in my case the user will only log out when he goes home already that means he will just log out once..
i have tried the code and honestly i don't know where to properly place it that's why i'm having this error...
i'm not really that good with this

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#11 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: adding items to listview

Posted 10 October 2012 - 04:31 PM

OK, in your original code you were putting something in both In and Out and since you are now no longer doing that you don't have a subitem(2) all you added was a subitem(1) so subitem(2) doesn't exist in the listviewitem.

What you can do easily is fix your login code to add another subitem of a 0 length string.
ListView.SubItems.Add("") after you add the time from the clockin and that should allow you to set it in clockout.
Was This Post Helpful? 0
  • +
  • -

#12 jhedonghae  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Re: adding items to listview

Posted 10 October 2012 - 10:30 PM

View PostCharlieMay, on 10 October 2012 - 04:31 PM, said:

OK, in your original code you were putting something in both In and Out and since you are now no longer doing that you don't have a subitem(2) all you added was a subitem(1) so subitem(2) doesn't exist in the listviewitem.

What you can do easily is fix your login code to add another subitem of a 0 length string.
ListView.SubItems.Add("") after you add the time from the clockin and that should allow you to set it in clockout.


i'm sorry but how am i going to do that? i really don't have an idea
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1