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




Listview Dragging Item


Hello, Jusk asking if there is a possible way to drag item in the listview??

it goes like this:

Listview populate with;

Item 1
Item 2
Item 3

When I drag Item 3 to the position of Item2, it goes like this;

Item 1
Item 3
Item 2


is this possible?? if not?? what should I do??




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Stop Item Dragging/moving In ListView
Is there any way you can stop the user from moving the item position in a listview?? I need them to stay the same as i added them first by code, with them being fixed for the user and not allowing any movement of item position!

thanks!

Menu Item Dragging
One facility that Windows provides with certain menus is the ability to drag and drop items in them to different positions so that the user can re-order them (see for instance the Favorites menu in Internet Explorer and the Programs menu in the Start menu). So what if you want to have this sort of facility in your VB application? Can it be done?

The answer is yes, although clearly it can't be done with native VB, and it does in fact require subclassing of two separate windows. The attached project provides a demonstration of how it can be done. It emulates the design used in Windows 98, which is to have a bar appear over the menu to show where the menu item being dragged will be dropped. I have not explored emulating the design used in Windows XP, which is to have a translucent copy of the menu item being dragged appear as a drag icon, but no doubt the technique to do this would be similar, if more advanced.

The stages to allowing menu item dragging and dropping are:

1. Subclass the form that contains the menus. You will need to be comfortable with the concept of subclassing in order to understand the project. If you're not, try this thread by John.

2. In the subclassing routine for the form (WindowProc of SubClassForm), set the menus to be ownerdrawn. Code for this is courtesy of Garrett Sever at EliteVB .

3. Obtain the hwnd of the menu window. This is NOT the same as the handle to the menu, which all APIs to do with menus seem to use. Instead it is the handle to a window that contains the menu. You could get this through looking for the WM_ENTERIDLE message in the form subclassing routine, which gives it to you, although I do it by waiting until the first item in the menu is drawn, and then finding it with FindWindow.

4. Subclass the menu window. This is the key to the whole thing. All of the following steps are carried out in the menu window subclassing routine (MWProc of SubClassMenuWindow). The form subclassing routine does not give you sufficient messages to provide for menu item dragging, so you have to do this.

5. When the left mouse button goes down on the menu (MWM_MOUSEDOWN, MWM_MOUSEDOWNWIN98 messages), record where it does.

6. If the mouse moves (MWM_MOUSEMOVE message) outside the drag rectangle without coming up, begin a drag operation. Get a device context for the menu window, and draw a bar onto that device context to show where the menu being dragged will be dropped if the user releases the left mouse button.

7. When the left mouse button comes up (MWM_MOUSEUP, MWM_MOUSEUPWIN98 messages), don't call the original window procedure. Instead, re-arrange the data which your menus represent, and cause the menu window to be refreshed by use of InvalidateRect. This allows the user to see the changes that he has made before the menu is dismissed.

And that's about it. It is complicated, and it is otherwise undocumented so far as I can see, but it does work. If you have any comments or find any bugs then please PM me.

If I Add An Item Onto A Form, How Do I Go About Dragging It Around?
I been searching on these forums but cant find anything using VB 6

Show Item Text When Dragging A Treeview Node
Does anybody know how when dragging a treeview node, to display the text property of the node as well as the DragIcon. I want to be able to replate the drag drop behaviour of Windows Explorer, i.e while you are dragging a folder, you can see the folder name in transparent text.

I have no problem setting the DragIcon property from an imageList I have associated with the treeview. For example in the DragOver event I am setting the DragIcon based on whether the mouse is over a valid drop point. E.g. .DragIcon = LoadResPicture("NoDrop", vbResCursor)

However it only shows the DragIcon and nothing else when dragging the node. Any help appreciated.

ListView DRAGGING
How can I select multiple items by clicking and then dragging over the amount of records that are there?

thanks...

Listview - Turning Off Dragging
I'm in one of my old apps and noticed that for some reason I used a listview control when a listbox "might" have done the job. My comments aren't as good as they should be (lesson learned). Anyway, since I'm not sure why I used a listview instead of a listbox I'm not willing to replace it. I don't have the time.

So... Is there a property (that I can't find) that turns off dragging of items in the listview control?

Thanks,
Bernie

Dragging And Dropping From One Listview To Another
Hi all,

How can I drag and drop multiple items including their subitems from one listview to another. Please help.

Thanks,
Nitesh

Dragging Listview Items
How to drag Listview Item to another form with the same format of Listview.??? hElp please??

Listview Icons And Dragging
Is it possible to have the listview Items containing icons not able to drag? If so how?

ListView And Turning Off Dragging
I have Listview with a number of items and I want a user to be able to select an item by clicking on it. Currently, if they click and drag then the icon and text go flying all over the window. How do you keep them from being able to click and drag on the icons messing up the entire list view but still allow them to click and select one? There are a number of related posts but noone seems to have a straightforward answer and this seems easy. Help please!

Thanks.

Click Item In Listview Then Show That Item In Combo As Index = 0
Hi guys,

I have a listview (lvwUserPunchedOut) that is populated with records in a database (persons first name in one column and last name in the second column), what I am looking to do is if I select a persons name by clicking on it in the listview on frmMain, and then bring up frmSearchCriteria, i would like to show that selected name in the combobox as default (cboEmployee.ListIndex = 0) on frmSearchCriteria (the combobox is sorted = True and is also populated with first name and last name of the person)

How would this be done? Hope I make sense. Thanks in advance.

Create Shortcut By Dragging From Listview
Was wondering if someone could show me an example of creating a windows shortcut by dragging an item out of a listview control and say onto the desktop.

When creating the shortcut I would like to link to a specifix .exe, but use what was dragged out as part of the command line parameters.

Thanks in advance

Listview: Disabling User Dragging
Is there a way to disable the user from dragging items in a listview. My listview.view=lvwIcon and has to stay that way (e.g. I need the nice large icons)

Thanks in advance,

Listview Setting No Column Dragging
Hi all
you know how with the listview columns you can drag them?
howdo i stop this or get it to resize as soon as the user drags it so its kind of asking howto set the drag to be undraggable


Tom

Dragging Multiple Items From A Listview
i have some code to let users drag an item from a listview onto a treeview node, which works fine, but now i want to let them drag multiple items.

the problem is that when then select a bunch of items, then drag them to the treeview, it leaves only the last item they clicked on selected (as if they selected them, then just left-clicked one of them). is there a way to keep them all selected?

also, just out of interest, is there a way to make the drag icon include some text from each selected listview item along with an icon (like when you drag multiple files in windows explorer)?

thanks for any help

Problem With ListView Control And Dragging
I'm trying to drag an item from one ListView control to another but whenever I click on any of the items the first item is selected no matter which I have clicked on. The drag outline does appear over the selected object though. The ListView control is in report view and all the other relevant code is below, can anyone suggest what I've done wrong?

Many thanks
Geoff

Setting up control:
Dim itmX As ListItem

lsvEvents.ListItems.Clear
lsvEvents.ColumnHeaders.Clear
lsvEvents.ColumnHeaders.Add , "Event", "Event", lsvEvents.Width / 2
lsvEvents.ColumnHeaders.Add , "Time", "Time", lsvEvents.Width / 2
lsvEvents.SmallIcons = imlLog

For each record in a recordset:
Set itmX = lsvEvents.ListItems.Add()
itmX.Text = !Name
itmX.Tag = !EventID
itmX.SubItems(1) = !OpenTime

Select Case !EventType
Case Is = "<Project File>"
itmX.SmallIcon = "Project"
Case Is = "<Resource File>"
itmX.SmallIcon = "Resource"
Case Is = "<Issue>"
itmX.SmallIcon = "Issue"
End Select

MouseDown:
Private Sub lstEvents_MouseDown(Button As Integer, Shift As Integer, x As
Single, y As Single)
Dim DY ' Declare variable.



DY = TextHeight("A") ' Get height of one line.
lblDrag.Move lstEvents.Left, lstEvents.Top + y - DY / 2, lstEvents.Width,
DY
lblDrag.Drag ' Drag label outline.
End Sub

Problem With ListView Control And Dragging
I'm trying to drag an item from one ListView control to another but whenever I click on any of the items the first item is selected no matter which I
have clicked on. The drag outline does appear over the selected object though. The ListView control is in report view and all the other relevant code is below, can anyone suggest what I've done wrong?

Many thanks
Geoff

Setting up control:
    Dim itmX As ListItem

    lsvEvents.ListItems.Clear
    lsvEvents.ColumnHeaders.Clear
    lsvEvents.ColumnHeaders.Add , "Event", "Event", lsvEvents.Width / 2
    lsvEvents.ColumnHeaders.Add , "Time", "Time", lsvEvents.Width / 2
    lsvEvents.SmallIcons = imlLog

For each record in a recordset:
                    Set itmX = lsvEvents.ListItems.Add()
                    itmX.Text = !Name
                    itmX.Tag = !EventID
                    itmX.SubItems(1) = !OpenTime

                    Select Case !EventType
                        Case Is = "<Project File>"
                            itmX.SmallIcon = "Project"
                        Case Is = "<Resource File>"
                            itmX.SmallIcon = "Resource"
                        Case Is = "<Issue>"
                            itmX.SmallIcon = "Issue"
                    End Select

MouseDown:
Private Sub lstEvents_MouseDown(Button As Integer, Shift As Integer, x As
Single, y As Single)
   Dim DY ' Declare variable.
   
   
   
   DY = TextHeight("A") ' Get height of one line.
   lblDrag.Move lstEvents.Left, lstEvents.Top + y - DY / 2, lstEvents.Width,
DY
   lblDrag.Drag ' Drag label outline.
End Sub

Disable Dragging Items In A Listview Control. Help, Help, Help
I don't know how to disable dragging items in a listview control. Please help me. thank you very much

Please Double Check This Dragging From ListBox To ListView Code For Me
I want to drag an item from a listbox to a listview so starting with my lisbox code:

Private DragID As Integer
Private blnAmDragging As Boolean


Code:
Private Sub lstUnalloc_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
DragID = lstUnalloc.ItemData(lstUnalloc.ListIndex)
End If
End Sub



Code:
Private Sub lstUnalloc_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
On Error GoTo errh

If Button = vbLeftButton Then
If lstUnalloc.ListIndex >= 0 Then
blnAmDragging = True
lstUnalloc.Drag vbBeginDrag
End If

End If

Exit Sub

errh:
errmsg "The following Exception occured : " & Err.Description & ", " & Err.Source & "", "Exception occured in frmMain.lstUnalloc_MouseMove ()"

End Sub


and now my listview:

Code:
Private Sub lvwPeople_DragOver(Source As Control, x As Single, y As Single, State As Integer)

On Error GoTo errh

If blnAmDragging = True Then
If State = vbLeave Then
Set lvwPeople.DropHighlight = Nothing
Else
Set lvwPeople.DropHighlight = lvwPeople.HitTest(x, y)
End If
End If

Exit Sub

errh:
errmsg "The following Exception occured : " & Err.Description & ", " & Err.Source & "", "Exception occured in frmMain.lstlist_DragOver()"

End Sub



Code:
Private Sub lvwPeople_DragDrop(Source As Control, x As Single, y As Single)

If Source = "lvwPeople" Then
Exit Sub
End If

Source.Drag vbEndDrag

Set lvwPeople.SelectedItem = lvwPeople.HitTest(x, y)

MsgBox lvwPeople.SelectedItem.Key
MsgBox DragID

End Sub


I just put 2 msgboxes to test. I have to write sql statements to assign the number to a person. I just need someone to check if I am doing the correct stuff for dragging and dropping.

Moving A Listview Item And Its Subitems To A New Listview
Hey Guys,

Having a bit of trouble. I am attemping to move a selected item and its subitems from one listview to another. I have no problem getting the contents of the first column, but I can't seem to get the subitems over.

Example: I have this in the first listview:

Code:
|Item |Quanity|Price |PQ |
Bananas 2 $.50 $1.00

Then when I try to move that whole row to the other listview I can only seem to get this:

Code:
|Item |Quanity|Price |PQ |
Bananas

No subitems . Any links or help would be appreciated.

Regards,

Max_Power

Get A Sub Item Of An Item On A ListView
Awhile go I used a Listview before on a project and I remember most of it. There is one thing I am having trouble with though. The list get's populated when the form is loaded. It has 2 headers "Item" and "Number". What I want to do, is when a button is pushed, msgbox the selected items number (In other words the sub item). How do I go about doing that?

How To Get The First Item In A Listview
This should be fairly easy, but for some reason nothing I've tried seems to work. I'm trying to visually pull out certain criteria in a listview. I'm using the following code to change the forecolor of the items in the listview. I can change the subitems, but can't figure out how to change the first item in the row.
Code:
If Trim(Rs![F14]) = "D" Then
For Y = 1 To Lvw1.ColumnHeaders.Count - 1
itmX.ListSubItems(Y).ForeColor = vbBlue
Lvw1.Refresh
Next Y
End If
I thought this would be easy to do. I've tried

lvw1.ListItems(Y).Forecolor (changes the first item in every row)
lvw1.SelectedItem.Forecolor (always changes the first item in the first row)

This has got to be simple enough. Can anyone tell me what I'm missing?

ListView Add Item
Hi

No doubt a nice simple one for someone but I am trying to use the ListView to display a set of records.

Can somebody tell me how to add a value to the listview? I have a recordset and I asume I need to cycle through it adding each value to the listview - but how?

Cheers

ListView Item
When a row is selected in a listview is there a way to get the value which may be in column 3 of the selected row?

Get Item # For Listview
How do I get the number of the item that is selected in the listview?

Listview Add Item
I added a listview to my form and right clicked on it and properties > column headers > add column i typed in the text i did this for 3 columns then clicked apply and then ok and i had to columns . Is that how im suppous to add columns?

Listview Add Item
how do i add an item to the second, third, fourth, fifth, etc column of a listview?

Add Item To Listview
when i add data to listview, why then new data goes to the top line, not the bottom line? thanks

Add Item To Listview
when i add data to listview, why then new data goes to the top line, not the bottom line? thanks

Add Item In Listview
How do I add a item in listview with data in different columns??

please!!

Item In A Listview
I want to get an specific item in a listview. I mean: I have several information displayed on a listview. If the User click on the listview on item X, i want to get the value of column Y.

Set A ListView Item By Key?
VB Code:
lvItem.SubItems(1) = "Text"


The above sets a ListView list sub item by index, but can I code the above to work by the .Key property somehow?


VB Code:
lvItem.SubItems("KeyName") = "Text"


Doesn't work...

I just realised that the 1st version is a pain if I reorder the columns in the listview. So, I'd like to access it by key, if I can, but it doesn't seem to provide that interface...

1st Item In ListView
Can anybody tell me the code to select the 1st item in a listview control?

I've tried the GetFirstVisible method, but it doesnt always select the top most item...

cheers.

Get Listview's Item Value
when clicking on the item of a listview, i hope to get the value of the item and the following subitem. how to do that??

Going To Next Item In Listview.....
Hey, I was wondering how you can go to the next item in a listview. It's easy in listbox, but I tried

listview1.listindex +1, etc. and it doesn't work

Thanks for any tips.

Going To Next Item In Listview.....
Hey, I was wondering how you can go to the next item in a listview. It's easy in listbox, but I tried

listview1.listindex +1, etc. and it doesn't work

Thanks for any tips.

Getting The Item In A Listview
I have three columnheaders in my listview. I am adding the hwnds of every window with the code in the first column. Here is the description

columnheader1 - > hwnds of the windows
columnheader1 -> Classname of the windows
columnheader1 -> Titlebar text of the windows

When I have about 3 rows in my listview (3 hwnds), I want to show the window(containing that hwnd) in a loop. I am using this little code but it shows me an error message saying "index out of bound":


Code:
Private Sub showall_Click()
Dim i, a As Integer

i = ListView1.ListItems.Count
For a = 1 To i
Call ShowWindow(ListView1.ListItems(a).Text, SW_SHOW)
ListView1.ListItems.Remove (a)
Next
End Sub



Do you know what is rong with that?

How To Add Item To Listview??
I manage to add in item into the first colum but failed to add to the second column. Here is my code

With de.rsContacts
    Do While Not .EOF
    Set Contact = Me.ListView1.ListItems.Add(1, , !FirstName)
    Me.ListView1.SelectedItem = lvItem.ListSubItems.Add(2, , !MiddleName) '2nd column
    Me.ListView1.SelectedItem = lvItem.ListSubItems.Add(3, , !LastName) '3rd column
    .MoveNext
Loop
.Close
End With

I have an error message for the 2nd and 3rd column. Can anyone tell me how to solve
??

Listview Item
hi,

i want to show a selected item at the top of the Listview control while in report view .

or
make other items visible =false or height=0

do you know how?

Thanks
Orko

Add An Item In A Listview
Hi!

In one of my form i have some textBoxes. The user enter the data that he want and when he press save button i would like that the data in each of the textBoxes will be put after the last record alreaydy in the listview. But we never know exactly how records the user has in his listview.

How can i add a record automaticly at the end of the listview without knowing the exact value of the index? Is it possible to have something like a dynamic index?

Thanks a lot

Listview Get Currently Selected Item
Is there a way to get the currently selecteditems text for a listview. I'm using vb 2005 and I don't see how to get a listview currently selecteditem. Someone please help me

Thanks for any help
Chris Ara

How To Sort The Item In Listview ?
This code to sort the item in listview only according by Column one.


Code:
ListView1.Sorted = True
How can I let the code work with another column?
Example: it sort according column 4

Show Last Item In Listview
Hello!

I'm using a listview in Excel Form. I'm add some itens manual (users entrys), but when the space defined to the listview ends the add item don't show in listview. The user must have to scroll the listview to see the add item.
It's possible to make automatic scroll of the listview to show the last add item ?
I can make this in the listbox, <userform.listbox1.ListIndex =userform.ListBox1.ListCount - 1 > but I can't make in the listview, because the propertys are diferent. I already try, but I can't do it

Thanks for the Help...

Select All Item In ListView
Hi,

I just wondering if there is way to select all items in my list view.Let say I had 20 items in my list data,so how can I select all the items in one time.


Thanks.

Add Listview Item At Runtime
Hi All,

does anyone know how to add item to the listview like you add things to the excel file. thanks. please advise.

Select First Item In Listview
Hi,

I have a somewhat simple problem and I am wondering what the simplest way to handle it is. I have a treeview that I am loading with some information about files in a specific directory. The listview is set to automatically sort the list and after all the nodes are added, I want to have the top node in the treeview be selected. But I don't have a reference to the first node in the list. Are there any properties that I can use to get the node that is at the top of the list?

Thanks,
Jason O

ListView Selecting An Item
Dear friends

I'm using ListView control, but I'm having problems to select/focus an datermined cell in the grid.
For example, I click in the second cell in the third line, nut thw focus alway happen to the first cell of the third line.
How I do to select/focus the cell that the user clicks?
Thanks and sorry about my bad english.

An Invisible Item In Listview.
Hey guys,

I have a small proble. infact it is a very small problem.

I am able to read all the contents of file into a listview. but when i scroll down to the botom, there is an empty space in the listview.I have triedto remove any empty spaces i the file thinking it could be coz of that.
But still the same.

This free space is the cause of all my trouble because when I do the sorting and searching of items it gives me a lot of head ache. ERR0RS!!!!!!!

P_lease helpme.

U guys helped me in previous occasions. please do i this.

darkshade

Listview Selected Item
How can i get the selected item of a listview in another form ???

I have tried with this code:


Code:
Public Function geselecteerdLid() As Integer
Dim iLidID As Integer
Dim oItem As ListViewItem
For Each oItem In lvwLeden.SelectedItems
iLidID = Convert.ToInt32(oItem.Text)
Return iLidID
Next
End Function
and in another form i refer to this with

Code:
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
Dim oForm As New frmLid
MessageBox.Show(oForm.geselecteerdLid)
End Sub
the result of this is always 0, i guess this is because i make an object of the form where my listview is (frmLid)

Copyright © 2005-08 www.BigResource.com, All rights reserved