-
Is there a DropDown list but like a ListView ?
I need a DropDown but the drop window I need it to look like a list view (but without the headers)
I have to list stuff like Name, Date, Title, Location in the DropDown, but I want the fields to be aligned and in a grid like a ListView.
Anything like that ?
I can probably make a control like that, but that takes time and I don't have that much time...
-
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...
Do you know for sure it's the control resizing ?
-
Re: Is there a DropDown list but like a ListView ?
-
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.
-
1 Attachment(s)
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 :confused:
Anyway here's the quick fix:
In the Usercontrol's DropFrm_frmItemClick sub, add this line just above DropFrm.Visible = False:
VB Code:
SetParent DropFrm.hwnd, 0&
-
Re: Is there a DropDown list but like a ListView ?
There is another problem, the dropdown stays open after you click on something else. It should close when you click on another object.
-
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 ?
Yes, but he can achieve it with resizing.
-
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.
-
1 Attachment(s)
Re: Is there a DropDown list but like a ListView ?
Yeey! I got it fixed. I have attached the latest codes.
The only things left now are:
-Colapse the dropdown list when somewhere else is clicked
-Bring to the top of ZOrder
Both have manual solutions, but it would be nice to automate them.
-
Re: Is there a DropDown list but like a ListView ?
Quote:
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 ?
Quote:
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 ?
Quote:
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.
-
1 Attachment(s)
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 ?
Quote:
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 ?
Did you check the latest code? I cant see a visual difference. Can you send a screen shot of what you mean?
-
1 Attachment(s)
Re: Is there a DropDown list but like a ListView ?
Here, the badly drawn arrows show the difference.
-
Re: Is there a DropDown list but like a ListView ?
Ok. I'll give you that :)
I'll see what I can do.
-
Re: Is there a DropDown list but like a ListView ?
Use the ExitFocus event for that instead of LostFocus. This collapses the list when the focus moves outside of the control. :)
VB Code:
Private Sub UserControl_ExitFocus()
Call ColapseList
End Sub
-
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 ?
:confused: It worked for me when I clicked on the form and not on a particular control...
-
Re: Is there a DropDown list but like a ListView ?
Strange... The latest codes are uploaded in the codebank so you can download them and see how they work
-
2 Attachment(s)
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).
http://www.vbforums.com/attachment.p...chmentid=37989
Have fun :)
-
Re: Is there a DropDown list but like a ListView ?
Thanks Joacim Andersson (and everyone else), i'll try it and get back to you if I need more help
-
1 Attachment(s)
Re: Is there a DropDown list but like a ListView ?
Baja_yu, this is the bug I was talking about:
-
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 ?
That is why I thought a form subclass is better, then just fire the Colapse procedure for every control.
-
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
-
Re: Is there a DropDown list but like a ListView ?
I think it's SetProp & GetProp...
-
Re: Is there a DropDown list but like a ListView ?
Did you try my solution? That doesn't have these problems.
-
Re: Is there a DropDown list but like a ListView ?
How do you handle the colapsing of the dropdown list?
-
Re: Is there a DropDown list but like a ListView ?
Quote:
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 ?
I see you use GetActiveWindow
Private Sub Timer1_Timer()
If GetActiveWindow <> Me.hwnd Then
Unload Me
End If
End Sub
I am wondering if it can be adapted to work with the listview control... hmm
-
Re: Is there a DropDown list but like a ListView ?
Quote:
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.
-
Re: Is there a DropDown list but like a ListView ?
Quote:
Originally Posted by baja_yu
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.
By the way.... it seems it's not as easy as you originally thought ? :)
-
Re: Is there a DropDown list but like a ListView ?
That's not a problem CVMichael, since if you use a MDI Form then your MDI Form is the main Form and you should declare the CPopupModifier object in that Form and call the AttachParent method in the MDIForm_Initialize event and the DetachParent in the MDIForm_Unload event. You can then use the popup on any child form and it all will look correct.
-
1 Attachment(s)
Re: Is there a DropDown list but like a ListView ?
Here's a modified version of my example that uses a MDI interface.
-
1 Attachment(s)
Re: Is there a DropDown list but like a ListView ?
I have managed to fix the problem with subclassing. Here is the fixed code.
-
Re: Is there a DropDown list but like a ListView ?
Nice baja_yu... the only thing I don't like is that I have to put code outside of the control (in the form).
By the way, I changed your subclassing to:
VB Code:
Private Const WM_LBUTTONDOWN = &H201
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wparam As Long, ByVal lparam As Long) As Long
If wMsg& = WM_ENTERSIZEMOVE Or wMsg = WM_LBUTTONDOWN Then
Call frmMain.ColapsLists
End If
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wparam&, lparam&)
End Function
This way you can take off the code in the Form_Click.
One thing I love about Joacim Andersson code is the way is doing the subclassing, I'ts subclassing only ONCE, and when you detach the one that is subclassing, the next one will start subclassing... that way, when you have a control array of dropdown boxes, and you add/remove through code, you don't have to worry about wich one actually does the subclassing... pretty cool...
But the problem is that both needs something outside the dropdown control...
The whole idea of a control is that you put it on a form and you start using it, not adding more code helping it work properly...
I'll have to think how to incorporate this in the control only...
-
1 Attachment(s)
Re: Is there a DropDown list but like a ListView ?
I altered the code a bit so that you don't have to put any extra code in the form.
The control subclasses the parent and keeps a collection of controls for collapsing all lists.
-
1 Attachment(s)
Re: Is there a DropDown list but like a ListView ?
Actually, the correction moeur made is excellent. I have just corrected the code so the project can be loaded. I noticed this before, once you compile the project, it changes the VBP files and sets the reference in that specific folder that the project is currently in. And if you dont correct it manually (with notepad or something) you wont be able to load the project on another system (unless it is in the same folder as it was compiled in).
In any case, if everyone is ok with the project now I will have it updated in the Utility Bank.
-
Re: Is there a DropDown list but like a ListView ?
Comments anyone?
If everybody is satisfied I will have this commited as the final version....
-
Re: Is there a DropDown list but like a ListView ?
I'll check it out when I get home (I'm at work right now)...
-
Re: Is there a DropDown list but like a ListView ?
Quote:
Originally Posted by baja_yu
Comments anyone?
OK, I will be mean and user-like in my criticisms:
- Doesn't use XP styles.
- Drop-down part doesn't slide like a normal combo box.
- If you click on the input area to drop the dropdown down, you don't see the drop-down button changing appearance when you press and release the mouse button.
- Listview part is a bit too wide, it goes right of the edge of the button.
- No column headers
Other than that it's looking pretty good :thumb: :D
-
Re: Is there a DropDown list but like a ListView ?
I made modifications to the control, I added a few properties like Font, BackColor, ForeColor, MaxRows, AutoResizeColums... it looks much better now...
But for some reason the "Manage Attachments" does not work !! I can't attach anything, nothing hapens when I click the button... :mad:
Anyways, I'll copy the project on my memory stick, and I'll try to upload from work (that will be about 10-11 hours from now...)
-
Re: Is there a DropDown list but like a ListView ?
I will fix sliding and the rest, and when CVMichael uploads his version I will add my corrections to them :)
-
Re: Is there a DropDown list but like a ListView ?
I have fixed everything except XP Styles. I am not sure how to aproach that problem.
I'll wait for Michael to upload his code.
-
Re: Is there a DropDown list but like a ListView ?
You will need to draw the theme background for the combo box drop down onto maybe a picture box, and then use the SetCapture and ReleaseCapture APIs to track the mouse movement.
If you like, when you merge your code with CVMichael's then I will have a crack at adding that part :)
-
Re: Is there a DropDown list but like a ListView ?
Sure, I'll upload the project once the codes are merged.
-
1 Attachment(s)
Re: Is there a DropDown list but like a ListView ?
OK, here it is...
Here's a short description of what I did:
Columns - I changed it so you can modify the # of colums at design time + run time (and more than once)
AutoResizeColumns - As the name says, it resizes the columns when you call it using the CTextSize.TextWidth from here: Get the width and height of a text without having a Form, thanks Joacim Andersson :)
MaxRowsToDisplay - You can choose the height of the ListView by how many rows to show in the ListView window (this one needs some fixing, does not work well when you have the horizonal scrollbar)
BackColor & ForeColor - same as other controls
Font - This was a tricky one, but I managed (found out how to do it from MSDN) - same as other controls
And I also fixed this: "Listview part is a bit too wide, it goes right of the edge of the button."
-
Re: Is there a DropDown list but like a ListView ?
Small bug I found: THe list view flashes in the top left corner of the screen momemtarily when it is opened.
Solution:
In the cmdDrop_Click() procedure, move the line
VB Code:
lstListData.Visible = True
so that it is below this line:
VB Code:
lstListData.Move ControlPos.Left + 2, ControlPos.Bottom, UserControl.ScaleWidth - 4, (oFont.TextHeight("W") + 1) * ColsHeight + 2
Other than that it looks good, now we have to wait for baja to merge his modifications in, then I will have a go at the XP styling part :)
-
Re: Is there a DropDown list but like a ListView ?
Your right...
Did you notice when you open the drop down the listview if "flashed" for a split second in the 0,0 position of the screen, then it goes where it should be.
Placing "lstListData.Visible = True" after "lstListData.Move" fixed the problem
VB Code:
lstListData.Move ControlPos.Left + 2, ControlPos.Bottom, UserControl.ScaleWidth - 4, (oFont.TextHeight("W") + 1) * ColsHeight + 2
lstListData.Visible = True
[edit]
wait a minute..... I just said the same thing as you ! :blush: (I guess I need some time to wake up)
-
1 Attachment(s)
Re: Is there a DropDown list but like a ListView ?
Ok, here it is. I'm going to drop *da bomb* on you.
If everything is ok, it's time for Penagate to do his magic and make the support for XP styles :)
P.S. Michael's modifications were more complex so I integrated mine into his code.
EDIT: I changed the attachment. I changed the colapseList procedure from Public to Private. There is no need for it to be public now.
EDIT2: Undo EDIT.
-
Re: Is there a DropDown list but like a ListView ?
Actually guys, I just found one major problem with our control. There's no way for the user to 'know' which item is selected...
We're missing the .SelectedItem property... :)