Looping Through A Listview And Adding Contents From One Listview To Another
i have my code for my old listbox but i need to convert it to the listview
any help?
Code: For i = 0 To frmmain.lstQY_IT_DES.ListCount lstprint.AddItem frmmain.lstQY_IT_DES.List(i) Next i
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Looping Through The Contents Of A Listview
How can I achieve the best way of looping through the contentents of a listview control in order to 'throw' all the data row, by row, to a rich text box? (in order to print them).
Thanx.
Michael Vlastos
Automation Engineer
Company SouthGate Hellas SA
Development Department
Athens, Greece
Looping Through A ListView
I have the following code which I intend to use to lend-out movies to my clients.:-
Code:
Private Sub cmdCheckOut_Click()
Dim li As ListItem
strSQL = "INSERT INTO trans1 (UserNo, TransDate) VALUES ("
strSQL = strSQL & cboPatron.ItemData(cboPatron.ListIndex) & ", "
strSQL = strSQL & "'" & dtpOrderDate.Value & "') "
cnAddMovie.Execute strSQL
' Insert all listed items in the ListView control
For Each li In ListView1.ListItems
'MsgBox li.Text
Set rsMovie = cnAddMovie.Execute("Select @@Identity")
lngNewId = rsMovie.Fields(0).Value
strSQL = "INSERT INTO trans_Details (transactID, TransTypeID, movie_inventoryId, ItemDueDate) VALUES ("
strSQL = strSQL & lngNewId & ","
strSQL = strSQL & cboTransType.ItemData(cboTransType.ListIndex) & ","
strSQL = strSQL & li.Text & ", "
strSQL = strSQL & "#" & dtpDueDate.Value & "# ) "
Debug.Print strSQL
cnAddMovie.Execute strSQL
Next
End Sub
However, instead of inserting all the movies that are in the ListView control, it only inserts the last item from the control. Where am i going wrong with my code?
Looping Through A ListView
I'm trying to loop through all entries of a lisview and see if a certain field is equal to something.
i can't get it to look through them though. This is the code I am using:
Code:
For k = 0 To lvQues.ListItems.Count - 1[indent]Debug.Print k & " = " & lvQues.ListItems(k).SubItems(4)[/indent]Next k
What am I doing wrong so that I can't get the text in the SubItems(4) through the loop?
Get Every X Row While Looping Through Listview
lets say i have two listviews, ListView1 and ListView2
ListView1 is populated already and has 8 columns (1 + 7 subitems)
is there a way to grab the row data from ListView1 and put it in ListView2, where i start from the *last* row and work up every X rows?
for example, listview1 might lok like this
c1a1 c2b1 c3c1 c4d1 c5e1 c6f1 c7g1 c8h1
c1a2 c2b2 c3c2 c4d2 c5e2 c6f2 c7g2 c8h2
c1a3 c2b3 c3c3 c4d3 c5e3 c6f3 c7g3 c8h3
c1a4 c2b4 c3c4 c4d4 c5e4 c6f4 c7g4 c8h4
c1a5 c2b5 c3c5 c4d5 c5e5 c6f5 c7g5 c8h5
c1a6 c2b6 c3c6 c4d6 c5e6 c6f6 c7g6 c8h6
c1a7 c2b7 c3c7 c4d7 c5e7 c6f7 c7g7 c8h7
and then i run a sub to loop through it from the bottom up getting the last one and every third one thereafter so ListView2 will look like this
c1a1 c2b1 c3c1 c4d1 c5e1 c6f1 c7g1 c8h1
c1a4 c2b4 c3c4 c4d4 c5e4 c6f4 c7g4 c8h4
c1a7 c2b7 c3c7 c4d7 c5e7 c6f7 c7g7 c8h7
Looping Through A ListView
I have the following code which I intend to use to lend-out movies to my clients.:-
VB Code:
Private Sub cmdCheckOut_Click()Dim li As ListItem strSQL = "INSERT INTO trans1 (UserNo, TransDate) VALUES ("strSQL = strSQL & cboPatron.ItemData(cboPatron.ListIndex) & ", "strSQL = strSQL & "'" & dtpOrderDate.Value & "') " cnAddMovie.Execute strSQL ' Insert all listed items in the ListView control For Each li In ListView1.ListItems 'MsgBox li.Text Set rsMovie = cnAddMovie.Execute("Select @@Identity")lngNewId = rsMovie.Fields(0).Value strSQL = "INSERT INTO trans_Details (transactID, TransTypeID, movie_inventoryId, ItemDueDate) VALUES ("strSQL = strSQL & lngNewId & ","strSQL = strSQL & cboTransType.ItemData(cboTransType.ListIndex) & ","strSQL = strSQL & li.Text & ", "strSQL = strSQL & "#" & dtpDueDate.Value & "# ) "Debug.Print strSQLcnAddMovie.Execute strSQLNext cmdCheckOut.Enabled = FalseEnd Sub
However, instead of inserting all the movies that are in the ListView control, it only inserts the last item from the control. Where am i going wrong with my code?
Looping Thru ListView
How can we loop thru a ListView?
For i = 0 to irlv.listcount
Arr(i) = I want the 5 column of each row to get in this array
next
Thanks in advance.
Looping And Listview How ?
Hi i got a question
i have the fuction below
VB Code:
Function xSign(lst As ListBox) Dim i As Integer For i = 0 To lst.ListCount - 1 lst.List(i) = Replace(lst.List(i), ">", ">") Next iEnd Function
replaces > to >
thing is how can i make this for a listview ?? in listview we cant do 1 to lst.listcount -1
Thanks to whoever helps
Regards
Looping Through The Listview
Im new to the listview, and i want to add 255 sub items. And i need them 0-255 for example:
VB Code:
Private Sub Form_Load() With lvwMain .ListItems.Add.Text = "0" .ListItems.Add.Text = "1" .ListItems.Add.Text = "2" .ListItems.Add.Text = "3" .ListItems.Add.Text = "4" .ListItems.Add.Text = "5" .ListItems.Add.Text = "6" .ListItems.Add.Text = "7" .ListItems.Add.Text = "8" .ListItems.Add.Text = "9" .ListItems.Add.Text = "10" .ListItems.Add.Text = "11" .ListItems.Add.Text = "12" .ListItems.Add.Text = "13" .ListItems.Add.Text = "14" .ListItems.Add.Text = "15" .ListItems.Add.Text = "16" .ListItems.Add.Text = "17" .ListItems.Add.Text = "18" .ListItems.Add.Text = "19" .ListItems.Add.Text = "20" .ListItems.Add.Text = "21" .ListItems.Add.Text = "22" .ListItems.Add.Text = "23" .ListItems.Add.Text = "24" .ListItems.Add.Text = "25" .ListItems.Add.Text = "26" .ListItems.Add.Text = "27" .ListItems.Add.Text = "28" .ListItems.Add.Text = "29" .ListItems.Add.Text = "30" End WithEnd Sub
all the way to 255. But it wolud take ages typing (or pasting). So ibe grateful if someone can show me how to loop through it code.
Thanks.
BTW the listview is set to Report view
Looping Through A ListView
I have a 3 column listview. There are multiple rows in it. When the user clicks an OK button, I need to build a comma delimited list with every value thats in the listview. Can someone please give me the code to do this.
Thanking you in advance
PORRASTAR
Looping Though A Listview (solved)
cant seem to find a tutorial on what im trying to achive.
I have a cost value at the end of each line in a listview, i want to loop thought the listview adding the value to a running total as i go.
Listviews confuse me somtimes
How Do I Read Subitems When Looping In A Listview??
Can someone show me an example code of how to loop through all of the items in a listview including the subitems? I got the items but do not know how to read the subitems without selecting them with the mouse first.
I did this so far:
For i = 1 To listview1.ListItems.Count
MsgBox listview1.ListItems.Item(i)
Next
How do I get the subitems for each listitem as I loop above? I need to assign them to string variables.
Thanks for your help!!!
Bind Data To Listview Control Without Looping
hi,
Could we bind data to list view control in VB6 like datagrid ? I know how to fill it using looping means using recordset and wihile loop. but my data is too larg nearly 1 Lacs so performance is very bad. i used access at backed
I use list view because i want to delete checked records and only listview control have their own checkbox.
Any body know better alternative for list view or Could anybody solve my problem?
Its very urgent for me.
Plase help me
How To Move Listview Item Blue Highlight While Looping Within It?
Hi all.I got this listview and i am looping within it but how to make the listview hightlight move each time i loop within its item. Now i don't see any highlight at all!!
:
2 Code:
Private Sub Command2_Click()
Dim i As Long
For i = 1 To ListView1.ListItems.Count
txtURL = ListView1.ListItems(i).Text
'ListView1.SelectedItem(i) = True
txtURL = ListView1.ListItems(i)
Dim completeurl As String
completeurl = "http://localhost/script.php?s=" & txtURL.Text
ListView1.ListItems(i).SubItems(2) = Inet1.OpenURL(completeurl, icString)
End Sub
Clear The Contents Of A ListView
I have created a form that uses ListView in Report format. How do I clear the contents of the listview so that I can update the data? Right now all I can get it to do is append to the end of the list, thus repeating most of the data.
In a standard listbox, you would just use:
list1.clear
Is there something similar for ListView that I'm just not seeing?
Transfer Listview Contents
How would I copy the listview items from one to another? for instance
listview1.listitems(2) = frmmain.listview3.listitems(2)
?
Printing Listview Contents?
how do you do that?
Printer.Print frmDetails.ListView1.text<---its not .text? so what?
also same question regarding a listbox? listbox1.??
thanks
Clearing Contents Of Listview
This sounds incredibly simple but I can't work out how to completely clear the contents of a listview, I can clear the column headers but not the actual content?
Much appreciated If anyone can help
Dan
Create PDF From Listview Contents
Hi, I found many threads where people ask how to create a PDF file. In a lot of those threads people are pointed to this code.
Generally it works fine, but every line or word needs to be positioned separately, but sometimes more than a 1000 rows (6 columns) need to be "written". Does anybody have any idea how to create a PDF from the contents of a Listview and keep everything in the right position, without having to position 6000 items manually? I'm absolutely clueless.
Saving Listview Contents
How would i go about saving a listview's contents for 8 columns and around 150 rows to .INI file? HELP PLEASE!
Saving The Contents Of A Listview
Im unsure of what is the most efficient way to save the contents of a list view. Then when the form loads again i need it to read from the database file or where ever it is. It ha to save the name and description as the list view has 2 column headers. Any thought of how or to what type of file i should save it to i would be grateful
Listview Contents Print
I Am Having Listview Control With Viewtype As Report..
I Want To Print Listview Control Details So I M Using Form.printform
But It Prints Only Column-headers Not It's Details ...
Why It Is So And Is There Any Solution To It ?
How To Save Listview Contents?
I have this listview where i add all the items recently entered by the user. for e.g., i add roomno and roomtype of a hotel in the listview. later when the user finishes up adding roominfo i want to save these info to the database. i thought i could access all those items in the listview through some property of listitem but i was dead wrong and now i am stuck. is listview used only to show data or can we save too? please tell me.
Clearing Contents Of A ListView
How do I clear the contents of a ListView? And it should clear the contents only where there's something in there. How can I do this?
How Can I Print Out The Contents Of A ListView Box?
I have a list view box in a form.
I am using the following code in a command button and the form prints out everything else...exept for the ListView box.
form1.Printform
Can anyone shed some light on this?
Cheers.
rastin
Printing Contents Of Listview??
Hey, I'm not sure if this is possible, but I'm wanting to have the contents of a listview control printed out when the user clicks the print button (Meaning I want to send to the printer, not print to the form). Any tips appreciated.
-Jeremy
How To Copy Listview Contents
I have a ListView with 7 columns of data and anywhere from 1 to 255 rows of data. I would like to be able to have the user right-click on the data and copy all of it to the clipboard. Probably would be best to have it in tab-delimited format. Any ideas? Thanks!!!
Editing The Contents Of 'listview'
Ok, what is a good way to constantly refresh the contents of a 'listview' control???
Another question. How could I change the text of every object, for example, column 3. If I were to disconnect everyone on a server (I'm the server) and wanted to display in the listview that each user's status is "Disconnected"... Thats what I mean..
Email Contents Of Listview?
any simple way of clicking a button and having the app bring up my default email handler and pasting the contents of a listview on my form called lv1
Thanks in advance.
Refreshing Listview Contents
Hi,
I have a vb app (let's say a.exe) in which there are 2 list view controls on the form. Items populated into listview1 are projects and when an item is clicked, the project's contents are populated into listview2. Doubleclicking on an item in listview1 opens the project in another vb app (let's say b.exe) a.exe will still be open.
Code looks like this.
public lvw1_dblclick()
Call Shell("c:program files.exe " & ProjectNo & " " & ArchiveAsx & " " & "False", vbNormalFocus)
end sub
Inside b.exe the User can work on the project (adding lot of new project contents). And when done closes the app.
AND HERE IS MY QUESTION. When user closes b.exe, i need to refresh the contents of listview2 with the user's changes inside b.exe.
From a.exe how do i know when the user closed b.exe and how to call lvw1_click automatically when b.exe is closed.
Thanks,
How To Save Contents Of Listview
Please help me,
i am developing an application where the data in the listview needs to be saved,
the document to be saved should be either html, notepad , or word
the data will be in table form .
so how to go about it ?????
Updating With Listview Contents!!
- suppose i have three fields in database table
-fields are ItemCode, stockremaining, and stock sold
-these fields already contains some data
- i have one listview in report mode
-it has three columns with header- item code, description and quantity
-these listview contains many listitems and subitems.
-i have one button on same form
- all i want to do is wheneever i click the button
it should update stockSold field of database with quantity column of listview,
stockremaining field with the result after subtracting field Stock and items from listview column "quantity". corresponding to each listview's first column itemcode.
Thanks
saracjl
Sabin Kumar Chhetri
Edited by - saracjl on 5/22/2005 10:18:04 PM
Printing Contents Of A Listview
How can I print the contents of a whole listview to paper?
Do I have to 'throw' the data to a txt, xls, or a data report? Or there is another easier way?
Michael Vlastos
Automation Engineer
Company SouthGate Hellas SA
Development Department
Athens, Greece
Printing A Listview Contents
I have three columns to be printed in my listview
Name Desc Explanation
I am not sure how to align the items under these
headings. Secondly, the Desc column and Explanation
need to have word wrap as their contents come from
a memo field in the database. Any ideas how I can do
something like this
Printer.Print "Name"; Space(30) & "Desc"; Space(50) & "Explanation"
For intCount = 1 To lsvGate.ListItems.Count
Printer.Print "" & lsvGate.ListItems(intCount).Text & _
"" & lsvGate.ListItems(intCount).ListSubItems(1).Text & _
"" & lsvGate.ListItems(intCount).ListSubItems(2).Text
Printer.Print vbNewLine
Next intCount
Printer.EndDoc
Please help and Thanks
Sam
This code works but it does not align stuff properly
Display Contents Of Listview In Different Colors.
How can we display the contents of listview in different color depending on some condition. I have set Listview1.View = lvwReport
i want something like :
dim litem as listitem
While Not rsFieldName.EOF
'Check for some condition
If rsFieldName.Fields("field") = 2 Then
??????
'SET FONT COLOR = RED
Else
??????
'SET FONT COLOR = BLACK
End If
Set litem = Listview1.ListItems.Add(, , rsFieldName.Fields("Caption"))
rsFieldName.MoveNext
Wend
Thanks in advance.
Copy Listbox Contents To Listview
Hi.
I need to copy the entire contents of a Listbox (List1) to a Listview (LvP).
The Listbox has a single column and the Listview has 2 columns.
Each entry in the Listbox is made up of two sets of information seperated by a Tab, eg, X tab Description
I need the information copied over to the Listview so that the X is in the 1st column of the Listview and the Description is in the 2nd column.
I seem to be going round in circles and not getting anywhere.
Any ideas.
Steve.
Copy Contents Of ListView To Word Doc
Hello,
Part of the VB app im working on requires that a report be copied to an MS Word doc, this is ok as so far it has been just VB TextBoxes copied to Word Bookmarks, but now I have a VB ListView and need to copy the contents to Word, does each item in the listview need to be copied to individual bookmarks or can I copy them to some sort of table or is there a listview in Word.
Any help would be much appreciated.
Thanks,
SKM.
Using A ListView To Show Contents Of A Folder
How do I use a ListView control to show the contents of a folder? I am currently using a FileList which is updated depending on the selections made in DriveList and DirList controls. Also, would I be able to use it to filter out hidden/system files and certain file extensions?
Cheers in advance!
Export ListView Contents To Excel
I have an application which has been working very smoothly for a long time. One of the things it does is populate a ListView with the contents of a backup SQL Query, all of which is working just fine.
This morning I received a request to 'dump' the contents of the the listview to an excel spreadsheet (I guess so folks can do more slicing and dicing)
Anyway, I've no idea how to do this. My initial thought was to simply rerun the query that populates the Listview, but dump the output to excel. Is that the best way to go, or is there a fairly easy way to just dump the listview to excel without rerunning the initial query?
Saving TextBox Contents Along With My Listview
Okay.. what I am doing is I have a form with a listview and 4 textboxes, and I am able to save the listview contents thanks to someone who put some nice code here. I would now liek to save the contents of the 4 text boxes alomg with the listview contents.
I able to save and Load the Listview with the following code:
[highlight=VB]
Private Sub mnuSave_Click()
With dlgAdd ' Common dialog.
.FileName = vbNullString
' The *.yft is the extension that the dialog will use to filter
' out the file list.
.Filter = "Datalogic List File|*.dlf"
.ShowSave
If .FileName <> vbNullString Then
' Save the listview's data.
saveListview ListView1, .FileName
End If
End With
End Sub
Private Sub mnuLoad_Click()
With dlgAdd ' 'nother common dialog.
.FileName = vbNullString
.Filter = "Datalogic List File|*.dlf"
.ShowOpen
If .FileName <> vbNullString Then
' Save the listview's data.
loadListViewData ListView1, .FileName
End If
End With
End Sub
Private Sub saveListview(ByVal objListView As ListView, ByVal strOutputFile As String)
' Saves the listview to the specified file.
Dim intFreeFile As Integer
Dim itmLoop As ListItem
Dim isbSubItem As ListSubItem
Dim strData As String
strData = vbNullString
For Each itmLoop In objListView.ListItems
' Build a comma (per column), carriage return (line) delimited string.
strData = strData & itmLoop.Text & ","
For Each isbSubItem In itmLoop.ListSubItems
strData = strData & isbSubItem.Text & ","
Next
' Remove the last comma & add a carriage return.
strData = Left$(strData, Len(strData) - 1) & vbCrLf
Next
' Remove the last carriage return.
strData = Left$(strData, Len(strData) - 1)
intFreeFile = FreeFile
Open strOutputFile For Output As #intFreeFile
Print #intFreeFile, strData
Print #intFreeFile, Text1.Text
Print #intFreeFile, Text2.Text
Print #intFreeFile, Text3.Text
Print #intFreeFile, Text4.Text
Close #intFreeFile
End Sub
Private Sub loadListViewData(ByRef objListView As ListView, ByVal strFile As String)
' Loads the listview with the data from the specified file.
Dim intFreeFile As Integer, intCounter As Integer
Dim itmAdd As ListItem
Dim strSplit() As String
Dim strLineRead As String
Dim Temp As String
intFreeFile = FreeFile
objListView.ListItems.Clear
Open strFile For Input As #intFreeFile
Input #intFreeFile, strLineRead
Text1.Text = strLineRead
Input #intFreeFile, strLineRead
Text2.Text = strLineRead
Input #intFreeFile, strLineRead
Text3.Text = strLineRead
Input #intFreeFile, strLineRead
Text4.Text = strLineRead
Do While Not EOF(intFreeFile)
Line Input #intFreeFile, strLineRead
If strLineRead <> vbNullString Then
' Split the line up into an array.
strSplit = Split(strLineRead, ",")
' Loop through the columns.
For intCounter = LBound(strSplit) To UBound(strSplit)
If intCounter = 0 Then
Set itmAdd = objListView.ListItems.Add(, , strSplit(0))
Else
If intCounter < objListView.ColumnHeaders.Count Then
itmAdd.SubItems(intCounter) = strSplit(intCounter)
End If
End If
Next
' Clear the array.
Erase strSplit
' And destroy the list item used for adding.
Set itmAdd = Nothing
End If
Loop
Close #intFreeFile
End Sub
[highlight=VB]
Obviously I have not done much with input/output...
Please help.. Thanx...
Exporting Contents Of ListView To Excel
I am currently using the following code to export the contents of a ListView to Excel. It works well with one exception. Contents are all exported into Excel as 'Text' type fields. Would like the ability to export some fields as numeric and some as text.
Here is the code I am referring to:
VB Code:
Private Sub ExportListViewtoExcel(LV As ListView) Dim LVHeader As Variant Dim LVData As Variant Dim LVData_Double As Double Dim X As Long Dim Y As Long Dim LVCol As Long Dim LVRow As Long 'Get Counts LVCol = CInt(LV.ColumnHeaders.Count - 1) LVRow = CLng(LV.ListItems.Count - 1) ReDim LVHeader(0) ReDim LVData(LVCol, LVRow) 'Create Header Array For X = 0 To LVCol ReDim Preserve LVHeader(X) LVHeader(X) = LV.ColumnHeaders(X + 1).Text Next 'Create Data Array For X = 0 To LVRow LVData(0, X) = LV.ListItems.Item(X + 1).Text For Y = 1 To LVCol LVData(Y, X) = LV.ListItems.Item(X + 1).SubItems(Y) Next Next OpenExcel LVData, LVHeader End Sub
Is there any way I can make this code dynamically export the field types to Excel?
|