PDA

View Full Version : [SOLVED:] Seletion problem in listbox (Userform)



stranno
01-19-2016, 09:13 AM
Hi,
I have included an example of a listbox of which the MultiSelect property is set to fmMultiSelectMulti.
However when using the textbox (to search) the MultiSelect property temporary changes to fmMultiSelectMulti
in order to show all possible answers. But this methode causes a selection problem. Who knows how to solve this?

regards,
Stranno

SamT
01-19-2016, 02:51 PM
MultiSelect property is set to fmMultiSelectMulti. ...
(Then) the MultiSelect property temporary changes to fmMultiSelectMulti
Is that a Typo?

stranno
01-19-2016, 11:34 PM
Sorry. Yes it's a typo. The first MultiSelectMulti should have been MultiSelectSingle.

stranno
01-19-2016, 11:41 PM
I see there's a typo in the title as well. Seletion must be selection of course.

snb
01-20-2016, 01:30 AM
I'd prefer to use doubleclick in the combobox or the listbox1 to add an item to listbox2.

stranno
01-20-2016, 04:18 AM
Yes, but In my project there are 10 listboxes to drag to. It depends on what the user wants to do with the dragged item.

snb
01-20-2016, 05:45 AM
Strictly speaking you don't need that listbox1 at all.

stranno
01-20-2016, 07:22 AM
In that case i prefer this solution because the search method is more suitable for my project.
The user, for example, looks for an item which contains the partial string "huur". Like in:
netto huur



huur incl btw
maximale huur



etc.
And this can't be achieved with the MatchEntry of a ComboBox.







But drag end drop is no option the way i'd like to do it?

In other words, isn't it possible to select one item in a multiple selection?






Perhaps in combination with the Shift key down?

snb
01-20-2016, 08:09 AM
The information you provide is as volatile as your requirements.

stranno
01-20-2016, 09:17 AM
I think i found a solution.

Private Sub ListBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim MyDataObject As DataObject
Dim Effect As Integer
On Error Resume Next
If Button = 1 Then
Set MyDataObject = New DataObject
If Len(Trim(ListBox1.List(ListBox1.ListIndex))) <> 0 Then
MyDataObject.SetText ListBox1.List(ListBox1.ListIndex)
Effect = MyDataObject.StartDrag
Set MyDataObject = Nothing
End If
End If
On Error GoTo 0
End Sub

I Changed ListBox1.value into ListBox1.List (Listbox1.ListIndex). And this seems to work.

Snb, I understand your remark partly. But you can't say that i have changed the subject.
I did have difficulties to select a single item in a multiselection within a ListBox.


Sometimes it makes sense to approach a problem from a different direction. Providing alternative ways to solve problems
is what you do sometimes. And i really appreciate that. But don't "accuse" me from volatility. Ok, i gave up names instead
of the real items (for privacy reasons) , but the principle remained the same. I wanted to drag and drop an item from one
ListBox to another with the means i provided (the TextBox and the ListBoxes).

snb
01-20-2016, 09:37 AM
You are on my ignore list now.

stranno
01-20-2016, 10:34 AM
I regret that because you are a great VBA programmer, and you've helped me several times. The thing is that helping lesser gods like myself is not a competition. And i can not help feeling that you consider it as such so now and then. Anyway, thanks for your help.

SamT
01-20-2016, 12:25 PM
I believe that you have to write your own custom DragAndDrop Method.

Here on VBAX:
Solved: Drag and Drop within VBA (http://www.vbaexpress.com/forum/showthread.php?454-Solved-Drag-and-Drop-within-VBA)

At MSDN
Performing Drag-and-Drop Operations in Windows Forms (https://msdn.microsoft.com/en-us/library/aa984430%28v=vs.71%29.aspx)Accomplishing drag-and-drop operations within Windows applications is done via the handling of a series of events, most notably the DragEnter, DragLeave, and DragDrop ...

stranno
01-20-2016, 12:51 PM
Thanks SamT but i've found a solution for my problem (#10). This worked for me.