Is there a DropDown list but like a ListView ?-VBForums
Page 1 of 5 1234 ... LastLast
Results 1 to 40 of 172

Thread: Is there a DropDown list but like a ListView ?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,726

    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...

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,726

    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 ?

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Other side of town from si_the_geek
    Posts
    7,171

    Re: Is there a DropDown list but like a ListView ?



    Has someone helped you? Then you can Rate their helpful post.

  5. #5
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,726

    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 ?
    Attached Files Attached Files

  7. #7
    Moderator
    Join Date
    Jan 2005
    Location
    Sydney
    Posts
    13,621

    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:
    VB Code:
    1. SetParent DropFrm.hwnd, 0&

  8. #8
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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.

  9. #9
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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

  10. #10
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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.

  11. #11
    Moderator
    Join Date
    Jan 2005
    Location
    Sydney
    Posts
    13,621

    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.

  12. #12
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Is there a DropDown list but like a ListView ?

    Yes, but he can achieve it with resizing.

  13. #13
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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.

  14. #14
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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.

  15. #15
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Talking 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.
    Attached Files Attached Files

  16. #16
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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.

  17. #17

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,726

    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.

  18. #18
    Moderator
    Join Date
    Jan 2005
    Location
    Sydney
    Posts
    13,621

    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.
    Last edited by penagate; Jun 26th, 2005 at 02:53 AM. Reason: typos ...

  19. #19
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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
    Attached Files Attached Files

  20. #20
    Moderator
    Join Date
    Jan 2005
    Location
    Sydney
    Posts
    13,621

    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.

  21. #21
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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?

  22. #22
    Moderator
    Join Date
    Jan 2005
    Location
    Sydney
    Posts
    13,621

    Re: Is there a DropDown list but like a ListView ?

    Here, the badly drawn arrows show the difference.
    Attached Images Attached Images  

  23. #23
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Is there a DropDown list but like a ListView ?

    Ok. I'll give you that

    I'll see what I can do.

  24. #24
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    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:
    1. Private Sub UserControl_ExitFocus()
    2.     Call ColapseList
    3. End Sub
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  25. #25
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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.

  26. #26
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Re: Is there a DropDown list but like a ListView ?

    It worked for me when I clicked on the form and not on a particular control...
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  27. #27
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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

  28. #28
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,450

    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:
    1. Private pop As PopupMod.CPopupModifier
    2.  
    3. Private Sub Form_Initialize()
    4.     Set pop = New PopupMod.CPopupModifier
    5.     pop.AttachParent Me.hwnd
    6. End Sub
    7.  
    8. Private Sub Form_Unload(Cancel As Integer)
    9.     If Not pop Is Nothing Then
    10.         pop.DetachParent
    11.         Set pop = Nothing
    12.     End If
    13. 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).


    Have fun
    Attached Images Attached Images  
    Attached Files Attached Files
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP

  29. #29

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,726

    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

  30. #30

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,726

    Re: Is there a DropDown list but like a ListView ?

    Baja_yu, this is the bug I was talking about:
    Attached Images Attached Images  

  31. #31
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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:
    1. Private Sub Form_Resize()
    2.         ctrlDropDownListView1.ColapseList
    3.         ctrlDropDownListView2.ColapseList
    4.         ctrlDropDownListView3.ColapseList
    5.     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.

  32. #32

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,726

    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 ??

  33. #33
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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.

  34. #34

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,726

    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.

  35. #35

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,726

    Re: Is there a DropDown list but like a ListView ?

    I think it's SetProp & GetProp...

  36. #36
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,450

    Re: Is there a DropDown list but like a ListView ?

    Did you try my solution? That doesn't have these problems.
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP

  37. #37
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Is there a DropDown list but like a ListView ?

    How do you handle the colapsing of the dropdown list?

  38. #38
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,450

    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.
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP

  39. #39
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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

  40. #40

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,726

    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.

Page 1 of 5 1234 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.