8 Replies - 1559 Views - Last Post: 13 September 2011 - 11:05 AM Rate Topic: -----

#1 moikzz214   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-September 11

I have problem with Listview

Posted 13 September 2011 - 06:54 AM

Hi! i have a problem of displaying my records to the listview.
i wanted to show the date, signin, signout and totalhrs but when i tried to run my code it will show the date only a

Listview is set to report
IDs.text is a Textbox

Dim SQL As String
Dim teach As Recordset
SQL = "SELECT timesheet.dDate, timesheet.signIn, timesheet.signOut, timesheet.totalhrs FROM timesheet ,user where timesheet.userID = '" + IDs.Text + "';"
Set teach = db.OpenRecordset(SQL)
Dim a As Integer

a = 1

Do Until teach.EOF
ListView1.ListItems.Add , , a
ListView1.ListItems(a).ListSubItems.Add , , UCase$(teach.Fields(0))
a = a + 1
teach.MoveNext
Loop



Is This A Good Question/Topic? 0
  • +

Replies To: I have problem with Listview

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: I have problem with Listview

Posted 13 September 2011 - 07:10 AM

Did you add more columns to the listview when you built the form?
Was This Post Helpful? 0
  • +
  • -

#3 moikzz214   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-September 11

Re: I have problem with Listview

Posted 13 September 2011 - 07:32 AM

Yes i did... i solved my problem, however, i have another problem displaying.

I only have 1 record/row in my table but when i tried to display it using the code below it display multiple or i say 4x even though there's only 1 record/row in my table
SQL = "SELECT timesheet.dDate, timesheet.signIn, timesheet.signOut, timesheet.totalhrs FROM timesheet ,user where timesheet.userID = '" + IDs.Text + "';"
Set teach = db.OpenRecordset(SQL)

If teach.EOF Then
MsgBox "There were no records in table"
Else
a = 1

Do Until teach.EOF
ListView1.ListItems.Add , , a
ListView1.ListItems(a).ListSubItems.Add , , UCase$(teach.Fields("dDate"))
ListView1.ListItems(a).ListSubItems.Add , , UCase$(teach.Fields("signIn"))
ListView1.ListItems(a).ListSubItems.Add , , UCase$(teach.Fields("signOut"))
ListView1.ListItems(a).ListSubItems.Add , , UCase$(teach.Fields("totalhrs"))
a = a + 1
teach.MoveNext
Loop


This post has been edited by moikzz214: 13 September 2011 - 07:33 AM

Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: I have problem with Listview

Posted 13 September 2011 - 07:42 AM

I see a lot of adding but I don't see you clearing the listview.
It seams you would want to clear it before you run the query otherwise you just pile on new results to old results.

In other words
If you put a breakpoint at line 10 and walk through the execution, does it execute the loop 4 times for your duplicate?
Or are you calling this block 4 times without clearing the listview?
Was This Post Helpful? 0
  • +
  • -

#5 moikzz214   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-September 11

Re: I have problem with Listview

Posted 13 September 2011 - 07:53 AM

when i put
ListView1.ListItems.Clear
before or after line 10 there's an error it say's out of bound

but when i put
ListView1.ListItems.Clear
before the
 Do 
still going to to display 4x even though there's only 1 row/record in my table
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: I have problem with Listview

Posted 13 September 2011 - 08:01 AM

That's because if you clear it there are no items in it.
ListView items are zero-indexed like everything else in the .NET world

First element is number 0
Second element is number 1

and you are starting your count at 1 instead of 0



I notice you didn't answer my question about what happens when you put a breakpoint in the code that adds to the ListView. Are you not familiar with breakpoints and debugging?
Was This Post Helpful? 0
  • +
  • -

#7 moikzz214   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-September 11

Re: I have problem with Listview

Posted 13 September 2011 - 08:05 AM

yeah sorry... what do you mean by breakpoint? i need to pause or something?
Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: I have problem with Listview

Posted 13 September 2011 - 08:42 AM

See FAQ #5 for debugging tutorials


FAQ (Frequently Asked Questions - Updated Sep 2011

Spoiler

Was This Post Helpful? 0
  • +
  • -

#9 Ionut   User is offline

  • D.I.C Lover
  • member icon

Reputation: 386
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: I have problem with Listview

Posted 13 September 2011 - 11:05 AM

Quote

SQL = "SELECT timesheet.dDate, timesheet.signIn, timesheet.signOut, timesheet.totalhrs FROM timesheet ,user where timesheet.userID = '" + IDs.Text + "';"

Do you have 4 users in user table? You make a full join here. Delete user table from the query and try again.

This post has been edited by Ionut: 13 September 2011 - 11:05 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1