By the way.... it seems it's not as easy as you originally thought ? :)Quote:
Originally Posted by baja_yu
Printable View
By the way.... it seems it's not as easy as you originally thought ? :)Quote:
Originally Posted by baja_yu
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.
Here's a modified version of my example that uses a MDI interface.
I have managed to fix the problem with subclassing. Here is the fixed code.
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:
This way you can take off the code in the Form_Click.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
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...
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.
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.
Comments anyone?
If everybody is satisfied I will have this commited as the final version....
I'll check it out when I get home (I'm at work right now)...
OK, I will be mean and user-like in my criticisms:Quote:
Originally Posted by baja_yu
- 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
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...)
I will fix sliding and the rest, and when CVMichael uploads his version I will add my corrections to them :)
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.
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 :)
Sure, I'll upload the project once the codes are merged.
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."
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
so that it is below this line:VB Code:
lstListData.Visible = True
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 :)
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
[edit]VB Code:
lstListData.Move ControlPos.Left + 2, ControlPos.Bottom, UserControl.ScaleWidth - 4, (oFont.TextHeight("W") + 1) * ColsHeight + 2 lstListData.Visible = True
wait a minute..... I just said the same thing as you ! :blush: (I guess I need some time to wake up)
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.
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... :)
rofl :lol: :D
Very nice work with the recent mods CVMichael and baja_yu. I will do the SelectedItem property as well as the XP styles then.
OMG ! :D :D :D
Now that is really funny.... none of us thought of it ! hehehe
I have changed the attachment again, I have changed the ColapseList back to Public as it is needed by the subclassing. Doh :(
Can you upload it again baja? When I try to download it it gives me the message "Invalid attachment".
Here it is here...
By the way, we should also make the usual events like Click, DblClick, Changed, KeyPress, KeyDown, KeyUp, MouseDown, MouseMove, MouseUp, GetFocus, SetFocus...
Ow, and I also want a sub so that the user can call the "Drop" window (in case you want to have the drop window open as default when you open the form for example). I sometimes wanted to do that with a regular DropDown.
I can do that, it's very easy, but... now I guess I have to wait for penagate to make his modifications :) (and of course I have to wait till I get off work)
If anyone can think of this kind of little features to add ?
Make it a "Friend", then it should be visible only in the drop down project...Quote:
Originally Posted by baja_yu
You can use SendMessage, I think it is CB_SHOWDROPDOWN or something like that ;)Quote:
Originally Posted by CVMichael
Now I will shut up and get back to coding :p
Let's leave it as Public then, so we have it along with the Drop procedure.
Could one of you tell me how the control's height is determined? I've been looking through the code but can't find it. Its' fixed size is too tall.
Controls size is determined by the font size that you select. Choose a smaller font size and the control will shrink too.
In the cmdDrop_Click() event:
[edit]VB Code:
If lstListData.ListItems.Count < lngMaxRows Then ColsHeight = lstListData.ListItems.Count Else ColsHeight = lngMaxRows End If lstListData.Move ControlPos.Left + 2, ControlPos.Bottom, UserControl.ScaleWidth - 4, [b](oFont.TextHeight("W") + 1) * ColsHeight + 2[/b]
I just realized I named the variable wrong, it should not be ColsHeight , it should be RowsHeight
And, it's handled in the Resize event:
VB Code:
Private Sub UserControl_Resize() Dim FntSize As Single FntSize = oFont.TextHeight("A") * Screen.TwipsPerPixelY If lstListData.Visible = False Then If UserControl.Height > FntSize + 120 Then UserControl.Height = FntSize + 120 End If lstChoice.Height = UserControl.ScaleHeight lngChoiceH = lstChoice.Height cmdDrop.Height = UserControl.ScaleHeight - 90 End If lstChoice.Move 0, 0, UserControl.ScaleWidth, lngChoiceH lstListData.Move 0, 0, UserControl.ScaleWidth cmdDrop.Move UserControl.ScaleWidth - cmdDrop.Width - 45, 45 End Sub
Wait a minute, are you talking about the height of the DropDown list, or height of the control (when the list is NOT droped down)?
Thanks, got it. Now is there a way of setting both listviews' row heights? With size 8 Tahoma the control size is perfect, but the the listview rows are too short vertically.
I was talking about the height of the control, not the drop down. Sorry for the confusion.Quote:
Originally Posted by baja_yu
I'm not sure if it was mentioned yet but TrueDBCombo (made by APEX I believe) works just like you would want it to: dropdown supports multiple columns with the headers.
Is it free?Quote:
Originally Posted by RhinoBull
I can't see this, or I dont understand what you are reffering to.Quote:
Originally Posted by penagate
When you set the font size, both lists (the 'control' list which shows the selected item, and the dropdown list) change their row height based on the font size.