Re: Is there a DropDown list but like a ListView ?
You can make it very very easily (custom control). Simply use a listview (set view to report, create the number of columns you need and turn on the gridlines. Use a command button to create that button to drop the list down. Add some code for resizing the list and all that.
Re: Is there a DropDown list but like a ListView ?
I don't think that when you click on the drop down button resizes the control, I think it's another window that comes up and it's placed right under the control...
Re: Is there a DropDown list but like a ListView ?
What manavo posted looks good (at least from the link), but you can make the control (custom one) do anything, resize it too. You have to code it though.
Re: Is there a DropDown list but like a ListView ?
I tried to make my own DopDown ListView, but I curently have problem with SetFocus.
The problem is that after I make a choice from the ListView, the form losses focus ! I tried differect ways to se the forus back, but it just does not do it !
Could anyone take a look at the project group attached to fix this ?
Re: Is there a DropDown list but like a ListView ?
I fixed it but it's a bit messy because when you click on an item, the form briefly loses focus because it is going to the Dropfrm, and then it goes back to the form. The solution to this would be to prevent the frmDrop from stealing the main form's focus. I know this can be done but I can't for the life of me think of the API to do it
Anyway here's the quick fix:
In the Usercontrol's DropFrm_frmItemClick sub, add this line just above DropFrm.Visible = False:
Re: Is there a DropDown list but like a ListView ?
This would be one solution. I added a procedure to colapse the list, but the bad thing is you would have to call it in the Click event of all objects on the form.
In the example it is only implemented for the List1
Re: Is there a DropDown list but like a ListView ?
One question, why did you create a sparate form (frmDrop), why couldnt you do it with just the control? I am not sure but I think that that will solve the focus problem.
Re: Is there a DropDown list but like a ListView ?
Well supposeing you have a small form, then the dropdown will be cut off by the form. If you have a combo box it hangs over the edge in its own window. I think that's the effect CVMichael is trying to achieve.
Re: Is there a DropDown list but like a ListView ?
Here it is. I have taken out the form and done it all on the control. And I was right, it does solve the focus problem.
But, it is not quite good yet. As you will see, it only works good for the list number 1 (the one with the items added) But for the other the position of the dropdown list is incorrect.
An the reson that the first one works is because it is hardcoded.
For some reason I can get the drop down list to align with the control position (Left and Top preoperties). If anyone can find the problem, please do.
Re: Is there a DropDown list but like a ListView ?
Here is another update on the control. I have got the get the top and the left correctly (the problem was that I did not change the SetParent of the list from the form to the UserControl), but it still gets an offset (try opening other lists and you will see).
There is one more problem now which I found a way to solve manualy, but it would be nicer if the control could do that by itself. And that is the ZOrder. You can see that I used ZOrder (on the test form) to set the control to the top uppon GetFocus. If that is not done the dropdown list stays below the other controls.
Re: Is there a DropDown list but like a ListView ?
Originally Posted by CVMichael
I don't think that when you click on the drop down button resizes the control, I think it's another window that comes up and it's placed right under the control...
Do you know for sure it's the control resizing ?
One more reason why I think it is resizing and not a new form (besides the focus problem) is that when you open the dropdown list, it is animated. It slides down, I dont think you are able to do that with a new form by just showing it. At least not without resizing that new form.
And if you are resizing, why not do it with the original control form and do everything on it.
Re: Is there a DropDown list but like a ListView ?
Originally Posted by penagate
Well supposeing you have a small form, then the dropdown will be cut off by the form. If you have a combo box it hangs over the edge in its own window. I think that's the effect CVMichael is trying to achieve.
Yup, I want to make it like a real DropDown...
I tried the modified project baja_yu, and it's pretty nice, but i would rather use a window instead of resizing the control. If you check you will see that the DropDown control is not resizing when you click on the DropDown...
I tried to make a window with CreateWindowEx API (to create a window without focus), but i could not do it. It did not create the window, and also it did not return the window handle, and ALSO, GetLastError did not return an error... the documentation (MSDN) says that if the CreateWindowEx return 0, then use GetLastError to get the error, but even that returns 0 ! After many tries I managed to crash my VB, and I did not save the CreateWindowWx project, so have to try again, but after I get some sleep.
Re: Is there a DropDown list but like a ListView ?
Originally Posted by CVMichael
ALSO, GetLastError did not return an error... the documentation (MSDN) says that if the CreateWindowEx return 0, then use GetLastError to get the error, but even that returns 0 !
Use Err.LastDLLError instead, GetLastError sometimes will return the result of the last API call VB made. LastDllError is always your own API call.
Last edited by penagate; Jun 26th, 2005 at 02:53 AM.
Reason: typos ...
Re: Is there a DropDown list but like a ListView ?
I still stand by it that it is not done with a new form. You can see two controls on vbaccelerator.com (combo boxes) and both are done without the separate form).
And to illustrate, look at this revised control and you will see that it acts the same way the regular combobox does.
If you find any difference (besides that it is a ListView dropdown) let me know and I will fix it
Re: Is there a DropDown list but like a ListView ?
Originally Posted by baja_yu
And to illustrate, look at this revised control and you will see that it acts the same way the regular combobox does.
If you find any difference (besides that it is a ListView dropdown) let me know and I will fix it
What I meant was, if you resize the form so that it is only as high as the non-dropped-down protion of the control, then when you drop it down it is obscured by the edge of the window. If you do the same with a regular combo box then the dropdown window appears outside the form, thus indicating it is its own window.
Re: Is there a DropDown list but like a ListView ?
Thanks for that , but it only works if another control is clicked. When I click on the form it doesnt colapse it. Anyway it simplyfies things greatly as you only need to write the colapse code in the Form_Click and not all the controls.
Re: Is there a DropDown list but like a ListView ?
The problem with having popup forms is that the Form owning the popup will lose focus. However this can be corrected but it's not the most simpliest task to do so. All VB applications have an invisible Form with the classname ThunderMain. To fix the focus problem you need to subclass this window and stripping of the WS_VISIBLE style at the correct time. The correct time is when your main form is created.
This means it has to be done before Form_Load since by then the Form is already created it's just not shown yet. Anyway I wrote a ActiveX DLL that takes care of all of this for you. You can use this DLL project for any types of popups and floating toolbars and such. The only thing you have to do is to create an instance of this object in Form_Initilize and call the AttachParent method. You must also call the DetachMethod before your Form is destroyed (in Form_Unload for example). Note that this is done for your parent form, not the popup form itself.
VB Code:
Private pop As PopupMod.CPopupModifier
Private Sub Form_Initialize()
Set pop = New PopupMod.CPopupModifier
pop.AttachParent Me.hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Not pop Is Nothing Then
pop.DetachParent
Set pop = Nothing
End If
End Sub
The attach project group contains the DLL + a demo project showing a popup form with a ListView control. The demo app just have a regular CommandButton that shows the popup but you can easily change that so that it looks like a combo box instead (see the attached image).
Re: Is there a DropDown list but like a ListView ?
Your right. There is one more problem similar to it. It gets messed up if you resize from the left. This will solve it, but, it is only a partial solution.
VB Code:
Private Sub Form_Resize()
ctrlDropDownListView1.ColapseList
ctrlDropDownListView2.ColapseList
ctrlDropDownListView3.ColapseList
End Sub
I was thinking of doing this, which would solve both problems (plus the one where you have to colapse it manually in the Form_Click event).
I thought I can subclass the mouse to capture a MouseDown event globaly, then use GetWindowRect on the Parent of the control. That way I can check if the click is targeted at the form (border and title bar included) and colapse the list. But then I will have to check to see if the click is on the list itself. So it gets kinda messy.
Is there a way to detect a click event on the form regardless where it is clicked? Because the Click, MouseUp and MouseDown events are not triggered when you click on a border or the titlebar.
Re: Is there a DropDown list but like a ListView ?
I was thinking maybe if you subclass the parent form like UserControl.Parent.hWnd, then you can get click events on titlebar also ?, and plus that you also have the move/resize events...
But then, i'm thinking every control that is placed on the form will subclass the parent, so if you place 10 dropdown controls, the form will be subclassed 10 times ! I think that is a little too much for VB to handle... Maybe there's a way to have a global subclass ??
Re: Is there a DropDown list but like a ListView ?
But then you have to write code in the form too, wich is not a good idea. I mean when you have a control, the idea is that the control will take care of everything.
I thought of another way.
Have the first control that you put on the form subclass the form (it's parent). Then it will set a global value (using API, I think it's GlobalAddAtom & GlobalFindAtom) When it gets the event to Collapse, then it will enumerate the parent controls, and will tell all the other drop down controls to colapse also.
[edit]
I just realized, that won't work if you have more than one window with dop down controls open at the same time because of the GlobalAddAtom.... The value has to be set a form level... hmmm
Last edited by CVMichael; Jul 5th, 2005 at 12:29 PM.
Re: Is there a DropDown list but like a ListView ?
Originally Posted by baja_yu
How do you handle the colapsing of the dropdown list?
If this question was directed to me then the answer will be that I don't. I used a completly different approach and wrote a generic ActiveX DLL that you can use for any popup window or floating toolbar. It only makes sure that the owner Form doesn't lose focus (or at least doesn't appear to lose focus while in fact it doesn't have focus anymore) when you show your custom popup Form. So the example simply popup another Form where a ListView is placed.
Re: Is there a DropDown list but like a ListView ?
Originally Posted by Joacim Andersson
It only makes sure that the owner Form doesn't lose focus (or at least doesn't appear to lose focus while in fact it doesn't have focus anymore) when you show your custom popup Form.
If it never loses focus it will be a problem in my case, becase I want to use the control on a form that is a MDI child (while having other MDI child windows in the MDI at the same time).
If it never loses focus it will be confusion on wich is the current one selected.