Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

How To Move Listitems Inside A Listview


I have a typical scenario. I have a listview control and a up down controls. The listview is filled up using values inside a database. Now what I want is to move the listview items up and down according to up or down key pressed. Please help me.

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Move 2 Or Move Listitems With Drag Drop
Hi vb-forum:

I need to move among items into a list viewwith drag drop function, how can i move it? in this moment I can move just one but i need to move 2 or more in a group. I hope you can give me a tip.

Thanks in advance and regards.

Listview Listitems
Have filled a listview with checkboxes with ID, Lastname and firstname. I now want to add the ID to a collection but am having trouble identifying that all are in the collection. Here is what I have:

Dim i As Integer
Dim cCol As New Collection
With listview1
For i = 1 To .ListItems.Count
If .ListItems(i).Checked Then
lngID = .ListItems(i).Checked ' this returns True/False
lngid = .selecteditem 'returns the current item only
cCol.Add lngID
End If
Next i
End With
When one or all checkboxes are checked, I would like to 'collect' them to further manipulate the data.

Any help would be greatly appreciated.



Vb6 Listview Listitems?
I am having problems adding items to a listview with multiple headers in the details view type. Here is my code below, followed by the error I get when executing the code.


vb Code:
Open "C:WINDOWSTEMPgamLST" For Input As #1        For a = 1 To 5 Step 1            Line Input #1, TempSTR                        frmMain.ListView1.ListItems(a).Bold = Split(TempSTR, ",")(0)            frmMain.ListView1.ListItems(a).Ghosted = Split(TempSTR, ",")(1)            frmMain.ListView1.ListItems(a).Text = Split(TempSTR, ",")(2)        Next a    Close #1


Index out of bounds


On another hand, the file being opened is:

true,true,Test Program 1
false,true,Test Program 2
false,false,Test Program 3
true,false,Test Program 4
true,true,Test Program 5


Also, if this helps any, I have attached a picture of the listview's setup.

Listview Help: With Listitems
I am filling listitems with a recordset. I have fields like Count, Timestamp etc. How can I know at run time, the index of the listitem whose recordset reads Count? i.e it should browse through the listitems and find the index of rs!Count

Thanks for any input

Listview Help Please: With Listitems
ok, here is my latest challenge with listview.

I have a menu bar where I can add/remove the listview column headers dynamically. I succesfully implemented this considering 'AllowColumnReorder' property set to true.

Now, when I reorder the columns and I add/remove the column headers, the corresponding listitems are not being added/removed.

How can I take care so that, the corresponding listitem is added/removed. Thanks for all the input.

Find ListView ListItems Using Key
I tried searching this out, but "key" was too short a word and "ListView" and "Find" were way too common.

How to find ListView ListItems use key to find, please.

Passing A Listview.listitems
I am trying to pass a listview to a sub and I can only get it to work if i use a variant. is there a way i can get this to work by declaring it a listview instead?

This is basically what I have:

Public Sub FillGridData()
Dim lview as ListView

Set lView = MDIMain.ActiveForm.ListView
ChangeListColor lview.ListItems(1)
End Sub

Public Sub ChangeListColor(list As Variant) '<--This has to be variant?
list.ListSubItems(8).ForeColor = &HC0&
End Sub

Listview Listitems Question
Hi Guys,

I store a key in the first column of my listview. example

row 1,column1 = 750
row 2,column1 = 756

I perform a check for the quantity of the item no's above and if there is 0 then I add the key to a collection.

Then I loop through the collection and I need to loop through my listview items to check where the item number in the collection is equal to the item number in the listview.

but how can I ensure that if there are 3 or more items that match in the listview are selected and visible.

At the moment it doesn't work because each time I loop through the collection it starts the loop all over again for the listview.

Here's my code:

For k = 1 To Idont.count
notid = CInt(Idont(k))
For l = 1 To lvwNote.ListItems.count
If notid = CInt(lvwNote.ListItems(l).Text) Then
lvwNote.ListItems(k).Selected = True

End If
Next l
Next k

ListItems Swapping In ListView

Does anyone know how I can swap 2 ListItems in a ListView control when I press a button?

Thanks, Lior

Listview And Checked Listitems
I have a check listview. How do I get the listitem text to be highlighted when I check or uncheck the associated checkbox? I can get it to check by click on the text or highlighting the text with arrow keys but not the other way around. Thanks

Add Method In Listview.ListItems
I use a ListView control to implement a list of string. I don't do it with the usual ListBox 'cause I want to sort strings in descending order, and this is allowed by a ListView but no by ListBoxes.

When I want to add a string to my ListView I do the following:


VB says to me "Compile Error: '=' expected".

Where am I wrong?

Thank you for your help

ListView Visible ListItems
Is there a way to determine what ListItems in a Listview are visible within the view area?

The ListBox control has a TopIndex property that gives you a index number, but the Listview does not seem to have a equivelant

I know there is a GetFirstvisible method but this is text information not a index value

John G

How To Copy Listitems In Listview To Another Listview?
I have "LISTVIEW 1" with 8 columnheader, I just want to show only 2 columnheader together with its items in "LISTVIEW 2" . How I can do that? Have sample as starting point

ListView.ListItems.Add From Another Form/module

I'm new to this forum, and am still quite the newbie at VB.

I'd like to add items to a ListView on my main form from another form or module, and I'm having one heck of a time.

Here's the gist of what I'm trying to do...

Public Sub DrawList()
lvw.ListItems.Add , , ("Add Item")
End Sub

Call DrawList
----[end form]----

"Call DrawList" from the main form properly adds items to control "lvw".

However, neither of these two techiniques work:

Call frmMain.DrawList
----[end form]----

frmMain.lvw.ListItems.Add , , ("Add Item")
----[end form]----

What am I doing wrong?

Thanks in advance for any help!
- Brian

Print Listview Listitems And Columnheader
How to set the A4 paper to print the listview listitems and listview column header as lanscape or potrait?By default it print as potrait. So How to set the paper to print as lanscape if the columnheader reach the A4 limit margin size?


'Print Column Header
Dim head As ColumnHeader
Dim colColumnIndexes As Collection
Dim Idx As Long
Dim iTab As Long

Set colColumnIndexes = New Collection
iTab = 5
Printer.FontUnderline = True
'Print the column headers and load the collection of
'column indexes that will be used when printing the ListView data.
For Idx = 0 To printtext.List2.ListCount - 1
For Each head In Form5.ListView2.ColumnHeaders
If printtext.List2.List(Idx) = head.Text Then

Printer.Print Tab(iTab); printtext.List2.List(Idx);
iTab = iTab + 30
colColumnIndexes.Add head.SubItemIndex

End If


Printer.Print vbCrLf
'Print ListItem
Dim item As ListItem
Dim strItem As String
For Each item In Form5.ListView2.ListItems
iTab = 5
For Idx = 1 To colColumnIndexes.Count
Printer.FontUnderline = False
If colColumnIndexes(Idx) = 0 Then 'this is not a subitem, so print the listitem data
strItem = item.Text
strItem = item.ListSubItems(colColumnIndexes(Idx)).Text
End If
Printer.Print Tab(iTab); strItem;
iTab = iTab + 25


Multiline Tooltips For Listitems In Listview
Well because it was asked to be posted here is my example on how to use multiline tooltips for individual listitems in a listview control... you need the included class module and regular module.. but as far as what you have to code... you just have to put the tooltip text in the listitems tag property as done in the example.. SIMPLE!

Hiding Listitems In ListView *RESOLVED*
Is there an easy way to hide listitems in a listview in report mode? My application loads a customer list into a listview in report mode, with checkboxes. Once the user checks all the checkboxes that apply, it'd be nice to have an option button to "show only checked items" similar to the Components selection screen in the VB IDE where you select which controls you want in the project. I don't see a property that allows this, but was wondering if anyone knows of an API that allows this. If not I can load the listitems into a collection first, then reload the listview from the collection to display them all, or remove the unchecked items to display only the selected ones.

Thanks in advance for any help.

Adding Listitems To Listview Is Slow
hiya, i'm adding listitems to a listview control (4 columns), but i'm adding over 500 listitems, and its taking about 8 seconds, during which time my app pauses. is there anyway to speed this up?

ps its coming from an access database and i dont really think i can speed up the data access or anything, its just the adding items to the list, in a loop

Organizing ListView ListItems By Color
Ok here goes: When I populate my listview based on a SQL query, certain listitems are assigned a diffrent color. That is, if a record meets certain criteria, I change the textcolor. I want to re-arrange the listitems grouped by color AFTER they have been populated. Anybody know the fastest way of doing it?

 Overspecialize and you breed in weakness.

ListView Sort Only Particular Listitems(rows)
I am working with a listview in vb6. If i want to sort the listitems i can set the sortorder and sort key,then if i set sorted = True,the listitems are sorted.
My query is to know whether there is any way in which i can sort only a particular range of listitems or rows in a listview and not all of them.

Remember Listitems Icon Position In Listview
hello everyone... is there a property i can set the position of the listitems in my listview? you know, just in windows explorer, it can remember the positions of listitems if the view is set to "Icons". hope you guys could help.

Visible Area Fill Of ListItems In ListView
When i am reading nearly 10,000 files from a location say MyDocuments and filling the listview , it is taking large time.

Is it possible to write code as how windows will handle like displaying the items of visible area and on scroll display the next set of data.

Thanks in Advance.

[RESOLVED- ALL THANKS TO MC BRAIN]ListView Counting The Number Of ListItems
Hi All,
I know recordcount property is not there in ListView, anyways, I'm trying to add all the ListItems from a ListView in Ms Access Table, but dont know how to go about it. In ListBox I could just run recordcount and then get a do While to get it working. But in ListView how do I save the ListItems into Ms Access Table and the number of ListItems vary from 1-6...

Listview: Weird Occurance On Set Itmx = LstViewQuery.ListItems.Add
On one of my forms i have a listview and items get added to the listview when the "add" button is clicked.
Heres the basic idea of the code

Dim itmx as listview
set itmx = listview1.listitems.add
itmx.text = cbo1.text
itmx.subitems(1) = cbo2.text
itmx.subitems(2) = cbo3.text

cbo1.text = ""
cbo2.text = ""
cbo3.text = ""

All items get added to the listview perfectly fine the very first time the add button is clicked. If itmx.text is blank then records get added in order, each addition gets added below the previous one

However, if itmx.text from the first entry contains any character, the second time the add button is selected, the second set of information gets added ABOVE the first one, when this should be below the first one.

The reason: This line of code seems to set the blank line above the first record.
set itmx = listview1.listitems.add

For example:
First time through:
cbo1.text = "test1"
cbo2.text = "test2
cbo3.text = "test3"

itmx.text = "test1"
itmx.subitem(1) = "test2"
itmx.subitem(2) = "test3"

Listview: (pipeline represents column)
line one: test1 | test2 | test 3

Second time the add button is clicked
cbo1.text = "test4"
cbo2.text = "test5"
cbo3.text = "test6"

itmx.text = "test4"
itmx.subitem(1) = "test5"
itmx.subitem(2) = "test6"

line one: test4 | test5 | test 6
line two: test1 | test2 | test 3

When it should be:

line one: test1 | test2| test3
line two: test4 | test5 | test6

Can anyone offer any suggestions as to why this occurs? Any help would be greatly appreciated.

Move By Dragging Inside The Window?
I've got a form that I have no border on, but I want to be able to drag it around the screen by using the picture box that is inside the form. Any ideas how I can do this?

Move Items Inside ListBox
Does anybody know how I could move items inside a ListBox like Winamp does? I am making an MP3 player and this is for the playlist.


Move Item Inside Listbox (up And Down)
Hey, anyone with a simple code for moving items up or down in a lsitbox?
I mean if you have the items 1 - 5 in a listbox,and you would like
the item5 to become item2, then you simply click item5, hold button and drop where item2 is and then we get a list that looks like this:

item1 ------ item1
item5 ------ item2
item2 ------ item3
item3 ------ item4
item4 ------ item5

Do you understand what i want? lets say its equal to winamp's behavior, for example...

Please help! PS: keep the code as simple as possible!

To Move Picture Inside A PictureBox

I'm trying to implement some functinality
that exists in many graphical editors and applications.

I have a PictureBox. I've load a Picture(.jpg or .bmp file) that is greater than the area of the PictureBox. I'd like to display only some fragment of the Picture inside PictureBox.

In the case when I say:

MyPicture.Left = -200
MyPicture.Top = 200

the picture moves together with a frame of PictureBox object.
It's not Ok for me. I'd like to display some fragment of the
Picture, but a frame of PictureBox would remain unmoved.

Thanks in advance.

Move Pictures Around Inside Of The Imagelist Control?
It seems like you should be able to do this but I can't figure it out.

Is there a way to shift around the location of images within the imagelist control?

Zoom && Move Image Inside Picturebox
I have a database of hi-res images (Antiques) of different sizes. Currently on the form I have various textboxes and a small imagebox displaying the image.

I would like to have a 2nd larger box of a set dimension (600x600) to put the image in and be able to zoom in and center any part, kinda like mapquest, or move the image within the frame, maybe by clicking or dragging on the image itself.

Move Pictures Around Inside Of The Imagelist Control?
It seems like you should be able to do this but I can't figure it out.

Is there a way to shift around the location of images within the imagelist control?

Grab Everything Inside Picture Box And Then Move It To A Smaller..........
I am creating a skin editor for my mp3 player , but when the user creates his skin i want the program to generate a preview thumbnail of the entire skin , this skin is created inside a picture with imageboxes inside them, how can i grab everything inside it and create a smaller thumbnail of it?

How To Move Record Pointer Inside Selected Recordset
how will i know the record pointer of this statement:

Dim conn As New ADODB.Connection
Dim recset As New ADODB.Recordset
Set recset = New ADODB.Recordset
Frame1.Enabled = False
Frame2.Enabled = False Connectstrings
recset.CursorLocation = adUseClient
recset.CursorType = adOpenDynamic
recset.LockType = adLockOptimistic

recset.Open "SELECT * FROM emp_tbl order by lname asc", conn
recset1.Open "SELECT * FROM emp_tbl where lname ='"& lnametxt.text &'"", conn

recset.moveprevious where recset1!lname=recset!lname

my lnametxt.text should be my record pointer in such a way i could movenext, moveprevious, movelast, movefirst other records.

Mouse-(down, Move, Up) Events To Select Cells Both Outside And Inside The Picturebox
I have a big picturebox (say picture1) and a smaller picturebox (say picture2) on top of picture1.

I am discretizing (dividing) the picture2 into subdomains (or cells). Then I am using mousedown, mousemove, and mouseup events to select a portion of cells and also recording which cells are selected (cells are stored in array with their physical locations known).

Things are working great as long as I stay inside picture2. I have been trying various ways to select the cells when I click and move from outside the picture2 box (while inside picture1) and then end either inside or outside the picture2 box. Similarly start inside the picture2 box and end outside.

Is there an easy way that I can't think of in order to achieve this?? Let me know if you want me to explain in further detail.

Thanks in advance,


HOWTO: Move Forms Inside A MDI Form But Will Not Exceed Through Its Window.
I want to move forms inside a MDI Form but these forms usually exceeded in MDI Form's window. (Try moving the forms inside a MDI Form). See? I want to fix that problem in my program.

Hope anyone from this forum could share a nice answer.


How To Show Information About A Menu Inside A Status Bar As U Move Mouse On It.
hi friends ..
plz help me , i wanna know how to make some information about the text in the menu of an MDI form appear in the status Bar as u move the mouse on the menu.
For Example :


suppose the mouse arrow was the (Star) on Delete in the menu , what i want to be shown in the Status bar is -- Click to Delete "Customer,item ....etc"
and as u move the mouse to another point the text in Status bar changes ..
Got it ?
Hope now u clearly understand my Qusestion.
Please try to reply to me as soon as possible , i am disprate fpr the answer

ListView "Selecting ListItems"
Lets say I have a ListView with 1 Column

...With 2 ListItems
"Item 1" & "Item2"

How would I be able to Select(or highlight)
"Item 1"(Or "Item 2") and then click a command button
to display which ListItem I have selected.

I know when you click off the ListView, you lose your focus.
So I will settle for having to click Or double click(If there is not an easy way to do it the first way) a ListItem to display which item I have clicked.(like in a text box or something)

Here is my Code...

ComboBox Inside A ListView
Dear friends,

I'm using a ListView control and it can use CheckBox inside it.
Can I use a ComboBox inside the ListView?

Getting The Tab Key To Work Inside A Listview
Hi team, does anyone know how to get the tab key working inside a listview? I want to be able to tab from column to coulmn



Controls Inside A Listview?
I was wondering if it is possible how would I add controls into a listview? I know I've read about doing a progressbar before with some Paint commands, but I want to put a ComboBox into a listview for example?

Is this possible and if so how could I achieve it?


Progress Bar Inside A Listview?
does anyone know how to put a progress bar inside a listview box with vb code and not manually? or is there something similar to the listview box that i can do this?

Create An ComboBox Inside A Listview
What I want to do is to create a combobox on each line of my Listbox. I assume you can't do this so I will opt for a ListView. Possible???

I want to select items from the combobox for each line in the list.

Problem Displaying Listview Inside Tab
Hi all i created 3 tabs so i be able to switch between webbrowser and listview but unfortuently after adding listview4 i keep getting this error:


Compile error:

Method or data member not found

and pointing to this line:


ListView4.Visable = False

Could any one tell me what i am doing wrong here.Thanks

1 Code:
Private Sub SSTab1_Click(PreviousTab As Integer)
If SSTab1.Tab = 0 Then
    WebBrowser2.Visible = True
    WebBrowser2.Visible = False
End If

If SSTab1.Tab = 1 Then
     ListView4.Visible = True
       ListView4.Visable = False
End If

'If SSTab1.Tab = 2 Then
'    WebBrowser4.Visible = True
'    WebBrowser4.Visible = False
'End If
End Sub

How To Filter Data Inside Listview
Hi all i got a huge list data inside my listview as shown in pic. One of the column name is URL. I want to filter the list to those url that this pattern exist on the their url .The bold parts are dynamic and is changeing .:
for example

http://localhost/AlbumSongs.asp?AlbumId=1734&Album=for life&Singer=Andy&SingerID=1383



I be happy if an expert show me how i can achive this easily and fast.Thanks

Center ListView Inside Of Frame
Hi Everyone,

How can I center a ListView control inside of a frame control, so that when a user resizes the form the ListView is always in the center of the frame? I would appreciate any help. Thanks.

Set Textbox Inside Listview SubItem
I need to "Float" a textbox over a listview subitem to make the
appearance of editing a subitem. I have the detection code for
which subitem was clicked and row, but everything I found was
using the x, y coordinates of the mouse click which does not
accurately position the textbox within the sub item.

How can I set a textbox coordinates to match the subitems
rectangular coordinates? Maybe something like getting the RECT
of the subitem somehow?


Search For Strings Inside A Listview
hi again

does anyone know of a way to search a listview box (2 coloums, report mode) for a string (Coloum 1 and is actualy a question) and then its corisponding string (coloum 2, same row and is the answer to question)?

btw, sorry for bad description

Checkboxes Inside Listview But Also Text
I have an Listview where I need to put some articles in and also checkboxes. How do I place them via code inside the listview and do I read out wich fields are checked?


Sand Hawk

Using Other Controls Inside The Listview Control
I wish to know if its possible to use another control, e.g a date picker, a text box, a combo box or other inside a cell (column,row) in a listview control just like it done in a flex grid. Thank you.

Copyright 2005-08, All rights reserved