Solved

MS Access VBA ListViewCtrl Object Positioning Problems

Posted on 2006-07-06
11
1,518 Views
Last Modified: 2012-05-05
Hi Everyone,

I have a MS Access VBA project and I've included Microsoft ListViewCtrl object on the form. When I fill the ListViewCtrl, the ListViewCtrl for some reason is displayed in the top left corner rather than where it's positioned. There's a white outline where the list control should be but the data and the column headers are at the top of the form.

Here's the code to fill up the list:

Private Sub FillRegistryList()
   
 
    If Me.TreatyNo.Column(0) <> "" Then
        Dim strSQL As String
        Dim rsFind As DAO.Recordset
        Dim intCount As Integer
        Dim lstitmAdd As ListItem
         
     strSQL = "Select * from tblRegistry where [TreatyNo] = " & Me.TreatyNo.Column(0)
     
         Dim db As DAO.Database
         Set db = CurrentDb()
       
         Set rsFind = db.OpenRecordset(strSQL, dbOpenSnapshot)
                           
                   DoCmd.Hourglass True
                           
                   DoEvents
                                           
                       Do Until rsFind.EOF
                             intCount = intCount + 1
                         Set lstitmAdd = Me![lstRegistry].ListItems.Add(, "'RegID = " & CStr(rsFind("RegID")) & "'", CStr(rsFind("RegID")))
                         lstitmAdd.ListSubItems.Add , , rsFind("MapID")
                         lstitmAdd.ListSubItems.Add , , CheckRSFields(rsFind("TreatyNo"))
                         lstitmAdd.ListSubItems.Add , , CheckRSFields(rsFind("Code"))
                         lstitmAdd.ListSubItems.Add , , CheckRSFields(rsFind("Qtr"))
                         lstitmAdd.ListSubItems.Add , , CheckRSFields(rsFind("Sec"))
                         lstitmAdd.ListSubItems.Add , , CheckRSFields(rsFind("Twnshp"))
                         lstitmAdd.ListSubItems.Add , , CheckRSFields(rsFind("Range"))
                         lstitmAdd.ListSubItems.Add , , CheckRSFields(rsFind("Acres"))
                         lstitmAdd.ListSubItems.Add , , CheckRSFields(rsFind("Land-type"))
                     
Nextrecord:
                           rsFind.MoveNext
                        Loop
                                   
                    rsFind.Close
                    Set rsFind = Nothing
                    DoCmd.Hourglass False
                    lblRegistryItems.Caption = "Registry Items(s): " & intCount & " "
   

    Me.Repaint
     
    End If
   
End Sub

Any advice is appreciated. Thanks for any assistance in advance!
0
Comment
Question by:mance
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 6

Expert Comment

by:AHMKC1
ID: 17049091
It shows top- left corner becuase you don't set its top and left properties

when you use this  'Dim lstitmAdd As ListItem' code it take default properties top=0 and left=0


set lstitmAdd.top and lstitmAdd.Left properties as you required

Thanks
0
 

Author Comment

by:mance
ID: 17050706
Thanks AHMKC1,

For some reason I'm unable to set the ListItem ... it almost seems like it's read-only.

I get the position for the ListViewCtrl and through each loop I set the ListItem control to the Left position of the ListViewCtrl and the Top position of the ListViewCtrl plus the row width. However, the ListItem doesn't seem to want to accept the new coordinates. Do I have to set the position elsewhere?

Thanks for your help.

Here's my code.

If Me.TreatyNo.Column(0) <> "" Then
        Dim strSQL As String
        Dim rsFind As DAO.Recordset
        Dim intCount As Integer
        Dim lstitmAdd As ListItem
       
       
        Dim PosX, PosY As Single
        PosX = lstRegistry.Left
        PosY = lstRegistry.Top
             
         
     strSQL = "Select * from tblRegistry where [TreatyNo] = " & Me.TreatyNo.Column(0)
     
         Dim db As DAO.Database
         Set db = CurrentDb()
       
         Set rsFind = db.OpenRecordset(strSQL, dbOpenSnapshot)
                           
                   DoCmd.Hourglass True
                           
                   DoEvents
                                           
                       Do Until rsFind.EOF
                             intCount = intCount + 1
                         Set lstitmAdd = Me![lstRegistry].ListItems.Add(, "'RegID = " & CStr(rsFind("RegID")) & "'", CStr(rsFind("RegID")))
                        lstitmAdd.Top = PosY + 210
                        lstitmAdd.Left = PosX
                         lstitmAdd.ListSubItems.Add , , rsFind("MapID")
                         lstitmAdd.ListSubItems.Add , , CheckRSFields(rsFind("TreatyNo"))
                         lstitmAdd.ListSubItems.Add , , CheckRSFields(rsFind("Code"))
                         lstitmAdd.ListSubItems.Add , , CheckRSFields(rsFind("Qtr"))
                         lstitmAdd.ListSubItems.Add , , CheckRSFields(rsFind("Sec"))
                         lstitmAdd.ListSubItems.Add , , CheckRSFields(rsFind("Twnshp"))
                         lstitmAdd.ListSubItems.Add , , CheckRSFields(rsFind("Range"))
                         lstitmAdd.ListSubItems.Add , , CheckRSFields(rsFind("Acres"))
                         lstitmAdd.ListSubItems.Add , , CheckRSFields(rsFind("Land-type"))
                       
                   
                       Debug.Print "lstitmAdd.Top=" & lstitmAdd.Top & " lstitmAdd.Left=" & lstitmAdd.Left
Nextrecord:
                           rsFind.MoveNext
                        Loop
                                   
                    rsFind.Close
                    Set rsFind = Nothing
                   

                    DoCmd.Hourglass False
                    lblRegistryItems.Caption = "Registry Items(s): " & intCount & " "
   

   Debug.Print "lstRegistry.Top=" & lstRegistry.Top & " lstRegistry.Left=" & lstRegistry.Left
   
    Set lstitmAdd = Nothing
     Me.Repaint
     
    End If
   
End Sub
0
 
LVL 84
ID: 17051755
I may be reading this wrong, but isn't the ListItem object is an actual item in the list ... it's not the actual Listview you're using ...

You can set the Top and Left properties of the ListView item directly:

Me.ListView2.Top = xx
Me.ListView2.Left = xx

I believe these are twips, so 1 in = 1440 (roughly)

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mance
ID: 17053292
Hi LSMConsulting,

ListItem is an item contained in lstRegistry. lstRegistry is a Microsoft ListViewCtrl. The problem is that the ListItems aren't being displayed in the proper position - they're not contained in lstRegistry but instead are displayed on the Top,Left position of the form.
0
 
LVL 84
ID: 17053509
I've got to ask - why are you setting the .Top and .Left properties of the ListItems? Typically you allow the ListView to handle the display characteristics of the listitems.

However, in your code, what are the values of PosX and PosY? Put a breakpoint in your code and type this in the Immediate window:

?Posx

?Posy

after the line where they are set ... betting you'll find some odd values there.

BTW, you have PosX being typed as a Variant. If you want both typed as Single:

Dim Posx As Single, PosY As Single

                       
0
 

Author Comment

by:mance
ID: 17054868
Hi LSMConsulting,

Thanks for the advice.

Read AHMKC1's comment on why I'm trying to set the position of the ListItems.

When I do a debug.print ( Debug.Print "lstitmAdd.Top=" & lstitmAdd.Top & " lstitmAdd.Left=" & lstitmAdd.Left) the values of the the ListItems aren't what I assigned to them and are positions set at the top, left part of the form. I don't know why, because the ListViewCtrl values are where they should be - that is the ListViewCtrl is a white outline and the data and headers are positioned off in the top left corner.

Hopefully this is somewhat clear. Am I forgetting to set some sort of property???

Thanks!
0
 
LVL 84
ID: 17054987
I guess my point is - why assign positions to the ListItems? I've seen a LOT of ListView code, and I can't recall seeing anyone set the .Top and .Left property of each individual ListItem ...

Have you tried commenting out these two lines:

lstitmAdd.Top = PosY + 210
lstitmAdd.Left = PosX

to see if your listitems show correctly in the Listview control?

If not, perhaps you could Zip your send your database to the www.ee-stuff.com website? If you login (using your EE username and password), you can click the Experts tab and upload your file there. Or, you can send it to me, and I'll be glad to do it for you.

0
 

Author Comment

by:mance
ID: 17055938
Thanks LSMConsulting for the generous offer.

I have a very crude solution ... the ListViewCtrl is contained in a TabControl and I noticed when you tab from the current page to a different page and then back the ListViewCtrl will display itself correct with all rows and columns contained in the list.

I don't know why this is, but if someone knows of why this is happening, I'd really like to know.

This is the silly code I used after I filled the list up with data:

    Me.PageTest.Visible = True
    Me.Cultivated.SetFocus
    Me.PageTest.SetFocus
    Me.Cultivated.SetFocus
    Me.PageTest.Visible = False

Thanks for everyone's efforts.
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 125 total points
ID: 17057275
Ahh ... on a tab control ... that's a different story. There are known issues with certain versions of the Listview and Access, the most common being the one you're describing. One common solution is to make the LIstview invisible, then only make it visible when your tab is in focus. Don't know why but this usually works

me.YourListView.visible = (me.YourTabControl= YourPageIndex)

You can do the above on the Tab's Change event.

Also, some use the Timer control to do this, but I tend to avoid this:

(note: set the Timer Interval = 1, or something like that)
Private Sub Form_Timer()
On Error Resume Next
Me.TimerInterval = 0
DoCmd.MoveSize , , Me.WindowWidth + 10, Me.WindowHeight
DoCmd.MoveSize , , Me.WindowWidth - 10, Me.WindowHeight
End Sub
0
 
LVL 27

Expert Comment

by:jjafferr
ID: 17461490
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Accept: LSMConsulting {http:#17057275}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

jjafferr
EE Cleanup Volunteer
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question