Problem in list view function..

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

31 Replies - 2337 Views - Last Post: 24 February 2012 - 06:42 PM Rate Topic: -----

#1 bry090911   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 02-February 12

Problem in list view function..

Posted 23 February 2012 - 07:09 AM

FOR COMMAND BUTTON 'TIME IN'
Private Sub cmdIN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdIN.Click
        lblempno.Text = txtempno.Text
        lblIN.Text = lbltime.Text & lbldate.Text
        MsgBox("Log in successful!", vbInformation)
        lv = ListView1.Items.Add(lbltime.Text)
        txtempno.Text = ""
        txtempno.Focus()

    End Sub


FOR COMMAND BUTTON 'TIME OUT'
Private Sub cmdOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOut.Click
        If lblIN.Text = "" Then
            MsgBox("Failed to save Log in first.")
            txtempno.Text = ""
            txtempno.Focus()
            Exit Sub
        End If
        If txtempno.Text = "" Then
            MsgBox("Please put your employee number", vbExclamation)
            txtempno.Focus()
            Exit Sub
        End If

        Try
            lblOUT.Text = lbltime.Text & lbldate.Text
            con2.Open()
            Dim cmd As New SqlCeCommand("insert into tbl_timerec(EmpNo, TimeIN, TimeOUT) VALUES('" & lblempno.Text & "','" & lblIN.Text & "','" & lblOUT.Text & "')", con2)
            dr = cmd.ExecuteReader
            dr.Read()
            MsgBox("Log out sucessful!", vbInformation)

            lv.SubItems.Add(lbltime.Text)

            con2.Close()

            lblIN.Text = ""
            lblOUT.Text = ""
            lblempno.Text = ""
            txtempno.Text = ""
            txtempno.Focus()
        Catch ex As Exception
            MsgBox("[ERROR]" & ex.Message)
            txtempno.Text = ""
            txtempno.Focus()
        End Try
    End Sub



E.G:
if the user1 time in and the user2 will time too, [hours later] if the user1 will use the time out it will go to the last row [last row is user2].

so i want is if the user1 will use the time out using his Employee number it will go to the row the when he time in.

Is This A Good Question/Topic? 0
  • +

Replies To: Problem in list view function..

#2 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1730
  • View blog
  • Posts: 5,709
  • Joined: 25-September 09

Re: Problem in list view function..

Posted 23 February 2012 - 07:25 AM

Is your employee number in your listview to match against?

In a screenshot you posted in another topic you did not have the employee number listed. So how can you tell which entry is which? If YOU can't tell by looking at a list of say... 10 users, how is your code going to be able to determine it?

This post has been edited by CharlieMay: 23 February 2012 - 07:28 AM

Was This Post Helpful? 0
  • +
  • -

#3 bry090911   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 02-February 12

Re: Problem in list view function..

Posted 23 February 2012 - 07:27 AM

i think my problem here is in the list view. but how? can you help me?
Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1730
  • View blog
  • Posts: 5,709
  • Joined: 25-September 09

Re: Problem in list view function..

Posted 23 February 2012 - 07:30 AM

how what?
I don't understand what you're asking that I didn't just give you the solution to in my previous post.
Was This Post Helpful? 0
  • +
  • -

#5 bry090911   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 02-February 12

Re: Problem in list view function..

Posted 23 February 2012 - 07:38 AM

if the user1 TIME IN and the user2 will TIME IN too, [hours later] if the user1 will use the TIME OUT it will go to the last row where the [last row is user2].

so i want is if the user1 will use the TIME OUT using his Employee number it will go to the row the where the place he TIME IN.. :whatsthat: :helpsmilie:

This post has been edited by bry090911: 23 February 2012 - 07:45 AM

Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1730
  • View blog
  • Posts: 5,709
  • Joined: 25-September 09

Re: Problem in list view function..

Posted 23 February 2012 - 07:54 AM

OK, Answer this question. Let's say you have 30 users and all have clocked in. (Keep in mind we're basing this only off the information that you have in the list)

Now user 7 comes to you and says write on my line that I just clocked out. Which of those 30 lines would you write that in? (AGAIN You ONLY have that list that is your listview to look at and you have no prior knowledge of what time he clocked in)

When you can answer this question then we can work on your solution.
Was This Post Helpful? 0
  • +
  • -

#7 bry090911   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 02-February 12

Re: Problem in list view function..

Posted 23 February 2012 - 08:09 AM

when they want to clock out they'll just put their employee numbers where the line that they log in. it should be like this

FROM THIS

NAME TIME IN TIME OUT

USER1 8:00am
USER2 8:00am
USER3 8:00am
USER4 8:00am
USER5 8:00am

TO THIS

NAME TIME IN TIME OUT

USER1 8:00am 8:00pm
USER2 8:00am 8:00pm
USER3 8:00am 8:00pm
USER4 8:00am
USER5 8:00am

just assume. :dozingoff:
Was This Post Helpful? 0
  • +
  • -

#8 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1730
  • View blog
  • Posts: 5,709
  • Joined: 25-September 09

Re: Problem in list view function..

Posted 23 February 2012 - 08:25 AM

So you are now putting the user in the listview?

Then you will need to loop through the rows of the listview until the userid you enter = the user in the list.
Once found get the index and use that information to update the clockout.
Was This Post Helpful? 1
  • +
  • -

#9 bry090911   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 02-February 12

Re: Problem in list view function..

Posted 23 February 2012 - 08:31 AM

i provide some code there. can you edit some of that? i can give you all my code and tools that i use.


Imports System.Data.SqlServerCe
Public Class DTR
    Dim lv As ListViewItem
    Dim dr As SqlCeDataReader
    Public con2 As New SqlCeConnection("Data Source=" & My.Settings.ASDDB)
    Private Sub tmrclock_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrclock.Tick
        lbltime.Text = TimeOfDay()
        lbldate.Text = Date.Now().ToString("d")
    End Sub
    Private Sub cmdIN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdIN.Click
        Dim dtchkempno As DataTable
        dtchkempno = empchk(txtempno.Text)

        If txtempno.Text = "" Then
            MsgBox("Please put your employee number to log in.")
            Exit Sub
        End If

        If dtchkempno.Rows.Count = 0 Then
            MsgBox("The Employee number is not on the database", vbExclamation)
            txtempno.Text = ""
            txtempno.Focus()
            Exit Sub
        End If

        lblempno.Text = txtempno.Text
        lblIN.Text = lbltime.Text & lbldate.Text
        MsgBox("Log in successful!", vbInformation)
        lv = ListView1.Items.Add(lbltime.Text)
        txtempno.Text = ""

        txtempno.Focus()

    End Sub

    Private Sub cmdOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOut.Click
        If lblIN.Text = "" Then
            MsgBox("Failed to save Log in first.")
            txtempno.Text = ""
            txtempno.Focus()
            Exit Sub
        End If
        If txtempno.Text = "" Then
            MsgBox("Please put your employee number", vbExclamation)
            txtempno.Focus()
            Exit Sub
        End If

        Try
            lblOUT.Text = lbltime.Text & lbldate.Text
            con2.Open()
            Dim cmd As New SqlCeCommand("insert into tbl_timerec(EmpNo, TimeIN, TimeOUT) VALUES('" & lblempno.Text & "','" & lblIN.Text & "','" & lblOUT.Text & "')", con2)
            dr = cmd.ExecuteReader
            dr.Read()
            MsgBox("Log out sucessful!", vbInformation)

            lv.SubItems.Add(lbltime.Text)
            lv.SubItems.Add(lblempno.Text)
            con2.Close()

            lblIN.Text = ""
            lblOUT.Text = ""
            lblempno.Text = ""
            txtempno.Text = ""
            txtempno.Focus()
        Catch ex As Exception
            MsgBox("[ERROR]" & ex.Message)
            txtempno.Text = ""
            txtempno.Focus()
        End Try
    End Sub

    Private Sub DTR_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblIN.Text = String.Empty
    End Sub
End Class


heres the screen shot for the tools that i use..

Posted Image
Was This Post Helpful? 0
  • +
  • -

#10 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1730
  • View blog
  • Posts: 5,709
  • Joined: 25-September 09

Re: Problem in list view function..

Posted 23 February 2012 - 08:56 AM

bry, you don't have to give all my posts a + vote, this is to signify that my post helped you and help others in this same situation. While others my find my posts useful, they apparently don't seem to be helping you to the point of marking them.

You need to research how to loop through a listview and understand how to determine what data appears on the row of the current loop iteration.

Search Help for For Each and For Next, Also ListViewItem specifically indexes. You don't seem to have these basics down. As I said in an earlier post, we're not here to write this for you. And as I linked to in a previous topic of yours, read the blog post from AdamSpeight2008 it's pinned at the top of this forum. There is a Wealth of information there.

I feel like I've given a lot of clues as to what methods and practices you need to research but you seem to just want someone to give you solutions with code so you can move on to your next problem.
Was This Post Helpful? 0
  • +
  • -

#11 bry090911   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 02-February 12

Re: Problem in list view function..

Posted 24 February 2012 - 06:24 AM

For Each item As ListViewItem In ListView1.Items
           If item.Text = lblempno.Text And item.SubItems(2).Text = "" then
                    item.SubItems.Add(2).Text = lbltime.Text
                End If
            Next



This is now what you said. But why it didn't add to the list view?but my msgbox say's successful :helpsmilie:
Was This Post Helpful? 0
  • +
  • -

#12 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1730
  • View blog
  • Posts: 5,709
  • Joined: 25-September 09

Re: Problem in list view function..

Posted 24 February 2012 - 06:36 AM

OK.. good, now we're getting somewhere.

You see where you checked if SubItems(2).Text = ""? That means you want to know if its blank and if it's blank, you want to update SubItems(2).Text to your lbltime.text

So all you will need to do is remove the .Add(2) and place the (2) index on the SubItems

In short, erase .Add from the line
Was This Post Helpful? 0
  • +
  • -

#13 bry090911   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 02-February 12

Re: Problem in list view function..

Posted 24 February 2012 - 06:46 AM

Nothings happen's.. i already tried that too. so whats the problem? :(


the msgbox say's that is successful but no item was added in the second column. :dozingoff:
Was This Post Helpful? 0
  • +
  • -

#14 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1730
  • View blog
  • Posts: 5,709
  • Joined: 25-September 09

Re: Problem in list view function..

Posted 24 February 2012 - 06:48 AM

Show me the line for that version where you tried it that way.
Was This Post Helpful? 0
  • +
  • -

#15 bry090911   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 02-February 12

Re: Problem in list view function..

Posted 24 February 2012 - 06:56 AM

For Each item As ListViewItem In ListView1.Items
                If item.Text = lblempno.Text And item.SubItems(2).Text = "" Then
                    item.SubItems(2).Text = lbltime.Text
                End If
            Next

This post has been edited by bry090911: 24 February 2012 - 06:58 AM

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3