Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Excel form refresh add more columns to ListView

Posted on 2011-03-11
7
Medium Priority
?
550 Views
Last Modified: 2012-05-11
I have an Excel form that uses a ListView to present data.  The user clicks on one of the rows and the row information appears in editing boxes.  However, when the user changes information, I want the form to refresh with the new data, that list, the listview reflect the changed information.  However, I tried calling the form's initallize event to refresh the ListView, but its add more columns to the ListView to the right.  It does show the chagnes, but I get extra columns.  That is, the orignal data columns appear, but another set of blank columns are added at the end.  I tried using Me.Repaint, but that does not refresh th form to reflect the new data.  So,how do I get the ListView to refresh its data after the user has made and saved the changes?
0
Comment
Question by:ssmith94015
  • 5
  • 2
7 Comments
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 2000 total points
ID: 35113589
>>> but its add more columns to the ListView to the right.  It does show the chagnes, but I get extra columns.

Clear the listview first :)

Sid
0
 

Author Comment

by:ssmith94015
ID: 35129864
Sid, sorry I have not gotten back, but my son and his wife live in Chiba in Japan and I have spent the last few days trying to find them.  They are safe and I will get to this question.
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35130020
Glad to know they are safe. That must have been a huge relief for you!

Please take your time :) Family First :)

Sid
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

Author Comment

by:ssmith94015
ID: 35130755
I have the clear method in the Form's initalize event, but that does not seem to prevent the extra columns when it is called again to refresh after a change.  I have attached the code.  This is actually inits own module that is called when the form is initialized so I also call it when I delete data.
'Need to figure out how to get rid of SalesLogic control at start of procedure and then
'add it back at the end to the reference library.
Dim lvItem  As ListItem
Dim i       As Integer

flgEdit = "No"
flgAdd = "No"

intRowStart = fntRangeStartEndsRows("Start", "ss_ACTQualitybreakdown")
intRowEnd = fntRangeStartEndsRows("End", "ss_ACTQualitybreakdown")

'Now initialize the listview box
    ListView1.ColumnHeaders.Add , , "Quality Breakdown", 90
    ListView1.ColumnHeaders.Add , , "LookUp Value", 75
    ListView1.ColumnHeaders.Add , , "", 0
    ListView1.ColumnHeaders.Add , , "", 0
    ListView1.ColumnHeaders.Add , , "", 0
    ListView1.ColumnHeaders.Add , , "Sort Order", 50
    

ListView1.View = lvwReport
ListView1.FullRowSelect = True
ListView1.ListItems.Clear
For i = intRowStart To intRowEnd
    Set lvItem = ListView1.ListItems.Add()
    lvItem.text = Worksheets("DataSource").Range("A" & i).Value
    ListView1.ListItems(ListView1.ListItems.Count).ListSubItems.Add , , (Worksheets("DataSource").Range("B" & i).Value)
    ListView1.ListItems(ListView1.ListItems.Count).ListSubItems.Add , , (Worksheets("DataSource").Range("C" & i).Value)
    ListView1.ListItems(ListView1.ListItems.Count).ListSubItems.Add , , (Worksheets("DataSource").Range("D" & i).Value)
    ListView1.ListItems(ListView1.ListItems.Count).ListSubItems.Add , , (Worksheets("DataSource").Range("E" & i).Value)
    ListView1.ListItems(ListView1.ListItems.Count).ListSubItems.Add , , (Worksheets("DataSource").Range("F" & i).Value)
Next i

Open in new window

0
 

Author Comment

by:ssmith94015
ID: 35130980
Sid, I figured it out!  When I call the InitializeListView1 event in the Delete code, it is doing exactly what I told it to do!  it is adding another set of column headers as it goes thorough the code.  I moved the code to a another module, called it ReinitalizeListView1, but took out the ColumnHeaders adding section.  Now, it does exactly what I want, refreshes the form with the correct data, but no extra columns are appended!
0
 

Author Closing Comment

by:ssmith94015
ID: 35130995
This worked to clear the items.  It prompted me to look further.
0
 

Author Comment

by:ssmith94015
ID: 35130998
Attached is the final version of what does work.
Private Sub ReInitializeListView1()
Dim lvItem  As ListItem
Dim i       As Integer

flgEdit = "No"
flgAdd = "No"

intRowStart = fntRangeStartEndsRows("Start", "ss_ACTQualitybreakdown")
intRowEnd = fntRangeStartEndsRows("End", "ss_ACTQualitybreakdown")

ListView1.View = lvwReport
ListView1.FullRowSelect = True
ListView1.ListItems.Clear

For i = intRowStart To intRowEnd
    Set lvItem = ListView1.ListItems.Add()
    lvItem.text = Worksheets("DataSource").Range("A" & i).Value
    ListView1.ListItems(ListView1.ListItems.Count).ListSubItems.Add , , (Worksheets("DataSource").Range("B" & i).Value)
    ListView1.ListItems(ListView1.ListItems.Count).ListSubItems.Add , , (Worksheets("DataSource").Range("C" & i).Value)
    ListView1.ListItems(ListView1.ListItems.Count).ListSubItems.Add , , (Worksheets("DataSource").Range("D" & i).Value)
    ListView1.ListItems(ListView1.ListItems.Count).ListSubItems.Add , , (Worksheets("DataSource").Range("E" & i).Value)
    ListView1.ListItems(ListView1.ListItems.Count).ListSubItems.Add , , (Worksheets("DataSource").Range("F" & i).Value)
Next i
End Sub

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

971 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