Listview in Userform doesn't display correct data

maria90

New Member
Joined
Apr 9, 2012
Messages
38
Hello

I'm working on a project which involves userforms and listviews.
I use a hidden sheet to get a customer's data (date, shopping date etc). The data is fetched as soon as a customerID is put into cell BN41 with an advanced filter. That works OK.

The problem is populating the listview with that data and sorting it. Sometime it works, sometimes it doesn't.
When it doesn't, it messes up all the data in that control and displays blank rows as well as the (correct) data.

I have attached a screenshot to this message.

zukoj6.gif


This is how I populate the listview:


Code:
Public Sub ListviewAufträge()
   
    Dim RowNumber As Long
    Dim MaxRow As Long


    With UserForm1.lvwAufträge
      .ListItems.Clear
      .ColumnHeaders.Clear
      .Gridlines = True
      .CheckBoxes = False
      .FullRowSelect = True
      .View = lvwReport


      With .ColumnHeaders
        .Add , , "ID", 1
        .Add , , "Datum", 100
        .Add , , "Zeit", 50
        .Add , , "Geschäft", 80
        .Add , , "Taschen", 40
        .Add , , "Betrag", 40
        .Add , , "Kurier", 80
      End With


      MaxRow = Tabelle1.Cells(Tabelle1.Rows.Count, 66).End(xlUp).Row
      For RowNumber = 5 To MaxRow
        .ListItems.Add , , Tabelle1.Cells(RowNumber, 66).Value
        .ListItems(RowNumber - 4).ListSubItems.Add , , Tabelle1.Cells(RowNumber, 67).Text
        .ListItems(RowNumber - 4).ListSubItems.Add , , Tabelle1.Cells(RowNumber, 68).Text
        .ListItems(RowNumber - 4).ListSubItems.Add , , Tabelle1.Cells(RowNumber, 69).Text
        .ListItems(RowNumber - 4).ListSubItems.Add , , Tabelle1.Cells(RowNumber, 70).Text
        .ListItems(RowNumber - 4).ListSubItems.Add , , Tabelle1.Cells(RowNumber, 71).Text
        .ListItems(RowNumber - 4).ListSubItems.Add , , Tabelle1.Cells(RowNumber, 72).Text
     
      Next RowNumber


    End With
End Sub

And this is how I sort it:

Code:
Private Sub lvwAufträge_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)With lvwAufträge
    .SortOrder = IIf(.SortOrder = lvwAscending, lvwDescending, lvwAscending)
    .SortKey = ColumnHeader.Index - 1
    .Sorted = True
End With
End Sub

I would be very greatful for your help as I have several listviews that need to be filled from this hidden worksheet. I got the code from a website or book - I cannot remember from which source.
I understand that the listview has an index, which in my case is the number 4. Could that be the problem? I do not exactly know what those indexes are. Could anyone explain to me what they are and used?

Thank you so much in advance for your help.

Maria

PS: I have asked thie same question to this forum. That message includes an example of my spreadsheet. I hope that it is OK to ask the same message on another forum, too.
http://www.ozgrid.com/forum/showthread.php?t=167829&p=619314#post619314
 
Last edited:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Re:Listview in userform to show data entred by textboxes and comboboxes

What I want to do here is to show data as soon as they are entered into worksheet .This step is already done,what remains is to show the data on listview as they are entered to make sure the data are already entered.I have this piece of code so far:
Private Sub cmdAdd_Click()
Dim ws As Worksheet
Dim FoundCell As Range
Dim Search As String
Set ws = Worksheets("STORAGE")
eRow = ws.Cells(Rows.Count, 2).End(xlUp).Offset(2, 0).Row
Me.Reg7.SetFocus


'Fill listview2 when data entered






'Fill Worksheet "STORAGE" with data entered via userform


eRow = Worksheets("STORAGE").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Search = Reg7.Text
Set FoundCell = Worksheets("STORAGE").Columns(6).Find(Search, LookIn:=xlValues, Lookat:=xlWhole)
If FoundCell Is Nothing Then
MsgBox "Numéro de facture n'existe pas sur la base de donnée! Vous pouvez continuer"
ws.Cells(eRow, 6).Value = Me.Reg7.Value
ws.Cells(eRow, 2).Value = Me.DTPicker1.Value
ws.Cells(eRow, 5).Value = Me.Reg8.Value
ws.Cells(eRow, 3).Value = Me.Reg9.Value
ws.Cells(eRow, 7).Value = Me.Reg10.Value
ws.Cells(eRow, 8).Value = Me.Reg11.Value
ws.Cells(eRow, 4).Value = Me.Reg1.Value
ws.Cells(eRow, 1).Value = Me.Reg2.Value
Else
MsgBox "N° de facture existe!" & " Données sur la plage " & FoundCell.Address & " Veuillez Refaire le N° de Facture"
End If


End With
End Sub



Tnaks in advance
 
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,958
Members
449,200
Latest member
indiansth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top