Mostrar Mensajes

Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.


Mensajes - chip

Páginas: [1] 2
1
Visual Basic 6 / Re:ucListViewEx 2.5 + clsIconList [UPDATED]
« en: Junio 22, 2011, 11:40:53 pm »
Here is an easy way to implement Multi Column Sort (supports 2 columns) :)

download:  http://www.convivea.com/download/ucListView2.5.2011.6.22.chip.rar

you can also change the Sort Order of each column at any time (independent of each other), and you can change what the 2nd Sort Column is, without re-sorting or losing your first "main" column.  i think its cool :)

http://www.convivea.com/multi_sort.png

For example, Header 1 is main and sorted first. Then Header 2 is clicked (with shift/cntrl). If you hold cntrl/shift and click Header 2, you will change only that column sort order. If you hold shift/cntrl and click Header 3, then Header 1 and Header 3 will be sorted.

Form:
Código: [Seleccionar]
Private Sub ucListView1_ColumnClick(Column As Long)
   
    On Error Resume Next
   
    Dim ncol As Long

    With ucListView1
   
        .AllowRedraw = False
       
        If (.Count > 1) Then
       
            'ADDED BY CHIP! - Support for Multi Column Sort
            If (m_CurrentColumn > -1) And CNTRLorSHIFT = True Then  ' Multi Column Sort
           
                For ncol = 0 To .ColumnCount - 1

                    If (ncol <> Column) And (ncol <> m_CurrentColumn) Then
                        .ColumnOrder(ncol) = soDefault
                    End If
                   
                Next ncol
               
                'SORT THE NEW COLUMN AND THEN SORT THE MAIN COLUMN AGAIN AFTER
           
                If .ColumnOrder(Column) = soAscending Then
                    .ColumnOrder(Column) = soDescending
                ElseIf .ColumnOrder(Column) = soDescending Then
                    .ColumnOrder(Column) = soDefault
                Else
                    .ColumnOrder(Column) = soAscending
                End If

                Select Case Column

                    Case 0: Call .Sort(Column, .ColumnOrder(Column), [stStringSensitive])

                    Case 1, 3: Call .Sort(Column, .ColumnOrder(Column), [stNumeric])

                    Case 2: Call .Sort(Column, .ColumnOrder(Column), [stDate])
                End Select
               
                'PREPARE SORT THE MAIN COLUMN AGAIN
                Column = m_CurrentColumn
           
            Else  ' Single Column Sort
           
                For ncol = 0 To .ColumnCount - 1

                    If (ncol <> Column) Then .ColumnOrder(ncol) = soDefault
                Next ncol
           
                If .ColumnOrder(Column) = soAscending Then
                    .ColumnOrder(Column) = soDescending
                ElseIf .ColumnOrder(Column) = soDescending Then
                    .ColumnOrder(Column) = soDefault
                Else
                    .ColumnOrder(Column) = soAscending
                End If
           
            End If

            Select Case Column

                Case 0: Call .Sort(Column, .ColumnOrder(Column), [stStringSensitive])

                Case 1, 3: Call .Sort(Column, .ColumnOrder(Column), [stNumeric])

                Case 2: Call .Sort(Column, .ColumnOrder(Column), [stDate])
            End Select

        End If
       
        Call .ColumnFocused(Column)
       
        m_CurrentColumn = Column
       
        .AllowRedraw = True
       
    End With
End Sub

Module.bas:
Código: [Seleccionar]
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Public Function CNTRLorSHIFT() As Boolean
    On Error Resume Next
           
    If (GetAsyncKeyState(160) And &H8000) Then  ' SHIFT
        CNTRLorSHIFT = True
    ElseIf (GetAsyncKeyState(162) And &H8000) Then ' CTRL
        CNTRLorSHIFT = True
    End If

End Function



Also:
Why GetFooterRECT & GetFooterItemRECT failed on Win7?

"The creation of footers in list-view controls is currently not supported." @  http://msdn.microsoft.com/en-us/library/bb774748.aspx

There is no Footer in a list-view control (yet).

2
Visual Basic 6 / Re:ucListViewEx 2.5 + clsIconList [UPDATED]
« en: Junio 20, 2011, 04:19:34 pm »
I can take a look at it, but I might not be adding much more to the control.  Can you modify the attached project to Fill the Data with an example of when MultiSort would be used?  (I am guessing when you have lots of the same identical values  in Column 1 and lots of identical values in Column 2)?

thanks,
chip

3
Visual Basic 6 / Re:ucListViewEx 2.5 + clsIconList [UPDATED]
« en: Junio 20, 2011, 05:21:36 am »
mi espanol es muy mal, pero aqui es un otro update para todos.

screen shot:  http://www.convivea.com/update.png

download:  http://www.convivea.com/download/ucListView2.5.2011.6.22.chip.rar


 2011.6.20: Added support for Unicode with ListItems and Columns Headers.
            Optimized: .Sort routines (about 2x as fast, and works with Unicode, and fixed DEFAULT sort order, works now :) )
            Updated FilterItems: added parameter to update the Filter after ItemAdd or new sub FilterReApply() to re-apply the filter after adding a large number of items (example: add a filter then hit the Fill button)
            Renamed FreezePaint(sub) to AllowRedraw (boolean property)
            Added: HeaderCheckBoxes style (thnx LeandroA & Jen)

gracias :)

4
Visual Basic 6 / Re:ucListViewEx 2.5 + clsIconList [UPDATED]
« en: Junio 15, 2011, 04:57:01 am »
1. Why Column Checkbox disappear after set MultiSelect =True or False on my Win7?
2. After disappear, I have to use command again to bring back Checkbox on header.
3. If we don't handle any of the notifications (HDN_ITEMCHECK and HDN_ITEMSTATEICONCLICK[/color), the default behavior is to select and unselect the items in the list view when clicking the checkbox. This isn't what I want. I want to Check on all items and keep items Selected state and Focused state.

Edited:
   Subclass HDN_ITEMSTATEICONCLICK to prevent the default behavior.

1 & 2: same for me. Not sure why. is there a window msg that we need to subclass and "eat" ?
3: Here is how I have implemented both the default windows behavior (Check All / Uncheck All) as seen in Windows Explorer and provided the option to only Toggle the Selected items:

note: this is not perfect example, but atleast allows for multiple options to be used from within the ColumnCheck raised event.


Events:
Código: [Seleccionar]
Public Event ColumnCheck(Column As Long, Value As Boolean, Cancel As Boolean)
Subclass:
Código: [Seleccionar]
                                    Case HDN_ITEMSTATEICONCLICK
                                       
                                        Dim bCancel As Boolean
                                       
                                        Call CopyMemory(uNMHE, ByVal lParam, Len(uNMHE))
                                       
                                        Me.ColumnCheckValue(uNMHE.iItem) = Not Me.ColumnCheckValue(uNMHE.iItem)
                                       
                                        RaiseEvent ColumnCheck(uNMHE.iItem, Me.ColumnCheckValue(uNMHE.iItem), bCancel)
                                       
                                        If bCancel = True Then
                                            bHandled = True
                                            lReturn = 1
                                        End If


Form:

Código: [Seleccionar]
Private Sub ucListView1_ColumnCheck(Column As Long, Value As Boolean, Cancel As Boolean)
    On Error Resume Next
   
    Dim x As Long
   
    With ucListView1
       
        If .Count = 0 Then Exit Sub
       
        .FreezePaint True
       
        If (.SelectedCount < .Count) And (.SelectedCount > 0) Then
           
            Cancel = True
           
            For x = 0 To .Count - 1
           
                If .ItemSelected(x) = True Then
           
                    .ItemChecked(x) = Value
               
                End If
               
            Next
       
        Else
   
            For x = 0 To .Count - 1
           
                .ItemChecked(x) = Value
               
            Next
   
        End If
       
        .FreezePaint False
       
    End With
   
End Sub

5
Visual Basic 6 / Re:ucListViewEx 2.5 + clsIconList [UPDATED]
« en: Junio 15, 2011, 03:35:15 am »
Be attention to use :
LVM_GETSELECTIONMARK and LVM_GETNEXTITEM,They might not be what you expect for MultiSelect.

Thank you Jen. My mistake. I missed that existing function because it was called "GetSelectedItem" and I was looking for "SelectedItem". It looks like if you remove the MultiSelect part, that will mimic VB6 functionality exactly as I wanted. What I have done is merged that existing function, removed what I previously added (included the m_SelectedItem in the subcass routine), and ended up with:

Código: [Seleccionar]
Public Property Get SelectedItem() As Long
   
    Dim lFlags As Long

    If m_hListView Then
            lFlags = LVNI_SELECTED
            If GetFocus() = m_hListView Then lFlags = lFlags Or LVNI_FOCUSED
            SelectedItem = SendMessage(m_hListView, LVM_GETNEXTITEM, &HFFFF, ByVal lFlags)
    End If
   
End Property


I tested on WinXP and Windows 7 and both has the same functionality as VB6's ListView.SelectedItem

6
Visual Basic 6 / Re:ucListViewEx 2.5 + clsIconList [UPDATED]
« en: Junio 09, 2011, 04:41:38 am »
sorry, you are right. i forgot to update all of the files in the .rar.

EDIT:  new file uploaded:

http://www.convivea.com/download/ucListView2.5.chip.2011.6.09.rar

7
Visual Basic 6 / Re:ucListViewEx 2.5 + clsIconList [UPDATED]
« en: Junio 09, 2011, 02:20:34 am »
hi again, im back with a working proof of concept:

image: http://www.convivea.com/capture.jpg

Download: http://www.convivea.com/download/ucListView2.5.chip.2011.6.09.rar

New:

GroupHeaderText:    Set Text and Get Text work on  Win 7 / Vista / XP.  Unicode works.
      note: use the text box next to the "Set Group 1" button to set your own text as the Group 1 header. If it is blank, it will use "Testing 1: & Chinese Unicode".


FilterItems:  Works in Group Mode or Single List mode (very cool! try it :) )

Also, GroupMode filter works on Win 7, Vista, XP both Service Pack 3 and Service Pack 2  (check for COM CNTRL 6.0, if not, it will default the old trick of changing the text to white/white. this Mode is for XP service pack 2 or less.)


.SelectedItem :  To provide a similar feature as the VB6 ListView control, I added a .SelectedItem property (Long, returns Item Index, not a reference to a ListViewItem).  Try double clicking a list item  (or right clicking as well)

Few other tweaks here and there  (like GroupAdd() allows Collapsible and IndexOrder parameters).

Known Issues:
Adding new items while the list is filtered does not properly auto-update the filtered listview. The ItemAdd function need to be updated.
FilterItems with Unicode probably does not work yet.



image2: http://www.convivea.com/capture2.jpg

here you can see both FilterItems modes (work the same on Win7/Vista/XP), Set Header Text on the left, .SelectedItem on the right.



EDIT:  I have found another (and better) work around to the Windows XP Set GroupHeader Text bug:

Código: [Seleccionar]
Public Property Let GroupHeaderText(ByVal GroupID As Long, newText As String)
'ADDED BY CHIP!

    If m_hListView Then
   
        Dim group   As LVGROUP_lp
        Dim lR      As Long
       
        Me.FreezePaint True
       
        If pIsXP = True Then  ' WINDOWS XP WORK AROUND
               
            'THIS WORKS BUT A NEWER WORK AROUND WAS FOUND
            'Dim x         As Long
            'Dim aGroups() As Long
               
            'ReDim aGroups(0 To Me.Count - 1) As Long
               
            'For x = 0 To Me.Count - 1
            '    aGroups(x) = Me.ItemGroup(x)
            'Next
               
            'Me.GroupRemove GroupID
            '
            'Me.GroupAdd GroupID, newText, , , , , GroupID
            '
            'For x = 0 To Me.Count - 1
            '
            '    If aGroups(x) = GroupID Then
            '
            '        Me.ItemGroup(x) = GroupID
            '
            '   End If
               
            'Next
           
            'NEW work around found:  http://users.skynet.be/oleole/Listview_grouping_feature.htm
            'Discusses the BUG with LVM_SETGROUPINFO
           
            With group
                .cbSize = Len(group)
                .mask = LVGF_HEADER Or LVGF_GROUPID
                .pszHeader = StrPtr(newText)
                .iGroupId = -100
            End With
       
            lR = SendMessageLong(m_hListView, LVM_SETGROUPINFO, GroupID, VarPtr(group))


            With group
                .mask = LVGF_GROUPID
                .iGroupId = GroupID
            End With
       
            lR = SendMessageLong(m_hListView, LVM_SETGROUPINFO, -100, VarPtr(group))

               
        Else
       
            With group
                .cbSize = Len(group)
                .mask = LVGF_HEADER
                .pszHeader = StrPtr(newText)
            End With
       
            lR = SendMessageLong(m_hListView, LVM_SETGROUPINFO, GroupID, VarPtr(group))
           
        End If
       
        Me.FreezePaint False
           
    End If
   
End Property

8
Visual Basic 6 / Re:ucListViewEx 2.5 + clsIconList [UPDATED]
« en: Junio 08, 2011, 02:00:36 pm »
From what I tested on XP/SP3 and VB6/SP6, GroupHeaderText can't be changed on runtime. But Vista/Win7 is OK. (Test String: ChrW$(&H6B22) & ChrW$(&H8FCE))
The Code your provided might be OK though there's a mistake:

 .cchHeader = Len(.pszHeader)  'Always is 4 because .pszHeader is defined in Long,Should be Len(newText)

Hi Jen, thanks for the comments. I looked at it further and actually cchHeader is ignored when using LVM_SETGROUPINFO, so that line should be commented out/removed:  http://msdn.microsoft.com/en-us/library/bb774769(v=vs.85).aspx


UNICODE:
Using my code, the Chinese characters ChrW$(&H6B22) & ChrW$(&H8FCE) do work on Windows XP SP3, both the IDE and compiled (vb6.exe needs manifest added). However, you will not see the characters unless you have East Asia Character support installed: http://www.cyberactivex.com/UnicodeTutorialVb.htm#Wheres_the_Beef_(Unicode)


GROUPHEADERTEXT:
From what I tested on XP/SP3 and VB6/SP6, GroupHeaderText can't be changed on runtime. But Vista/Win7 is OK. (Test String: ChrW$(&H6B22) & ChrW$(&H8FCE))

I dont know why, but, sometimes the group header text can be changed, other times no. I still don't know why :P Im testing that too on WinXP (If works in winxp it should work in vista/7 too)

raul338, I have experienced this problem too, no matter what code is used (even tried the example at vbAccelerator). Here is what I have found for Windows XP SP3:

1. Get the GroupHeaderText works (unicode/ansi).
2. Set the GroupHeaderText works (unicode/ansi).
3. Get the GroupHeaderText AFTER you Set the GroupHeaderText fails, everytime. No matter if you Set the GroupHeaderText with Unicode, or the method used to change the GroupHeaderText. It seems the Get GroupHeaderText will return "-1" everytime after you have Set the GroupHeaderText.

Possible work around for Windows XP (unless you guys have found a way to do that):

On Set GroupHeader Text:
    a.  Get the GroupHeader complete info
    b.  Remove the Group
    c.   Add the Group back with the new GroupHeader Text

Not sure how "fast" that will be or if there are any side effects. I have not had a chance to test that theory yet.


SORTING:
Looks like the ListView sorting should be changed from  "If var > var then" to use Unicode aware CompareStringW Lib "kernel32.dll":  #52 @ http://www.cyberactivex.com/UnicodeTutorialVb.htm#Sorting


Thanks !

9
Visual Basic 6 / Re:ucListViewEx 2.5 + clsIconList [UPDATED]
« en: Junio 07, 2011, 04:07:49 pm »
Gracefully :) resolve UNICODE for GroupHeader/GroupFooter/GroupSubtitle.

Código: [Seleccionar]
Public Property Get GroupHeaderText(ByVal GroupID As Long) As String

Dim tGRP As LVGROUPW

    tGRP.cbSize = Len(tGRP)
    tGRP.Mask = LVGF_HEADER
    GroupHeaderText = psGetGroupText(GroupID, tGRP, iGroupHeaderText)

End Property

Public Property Let GroupHeaderText(ByVal GroupID As Long, Text As String)

'//XP/SP3 doesn't support,For Vista/Win7 above

Dim tGRP As LVGROUPW

    tGRP.cbSize = Len(tGRP)
    tGRP.Mask = LVGF_HEADER
    If Not pbSetGroupInfo(GroupID, tGRP, Text) Then
        'MsgBox "Failed to set groupheader."
    End If

End Property


Hi Jen, thanks for the example. I am always looking to learn. Are you suggesting this is better than the solution I suggested? If so, would you mind sharing more? Does UNICODE chars not work with my solution? I see you have used HeapAlloc, LocalAlloc & CopyMemory which I had found to be a solution as well, but then I found it to work with the simpler StrPtr() and lstrlenW/lstrcpyW?

Also, I tested both Get GroupHeaderText and Let GroupHeaderText using my solution on both Win7 & Win XP and it worked. (however you had suggested Let GroupHeaderText '//XP/SP3 doesn't support,For Vista/Win7 above)

Please advise, and thank you.

Gracias ! :)

10
Visual Basic 6 / Re:ucListViewEx 2.5 + clsIconList [UPDATED]
« en: Junio 07, 2011, 03:54:34 am »
hi guys.. I fixed the  Public Property Get GroupHeaderText(ByVal GroupID As Long) As String

(previously crashed on Windows XP)
Declares
Código: [Seleccionar]
'ADDED BY CHIP!

Private Declare Function lstrcpyA Lib "Kernel32.dll" ( _
    ByVal lpString1 As String, ByVal lpString2 As Long) As Long
Private Declare Function lstrlenA Lib "Kernel32.dll" (ByVal lpString As Long) As Long
Private Declare Function lstrcpyW Lib "Kernel32.dll" ( _
    ByVal lpString1 As Long, ByVal lpString2 As Long) As Long
Private Declare Function lstrlenW Lib "Kernel32.dll" (ByVal lpString As Long) As Long

Private Type LVGROUP_lp
    cbSize                  As Long
    mask                    As Long
    pszHeader               As Long
    cchHeader               As Long
   
    pszFooter               As Long
    cchFooter               As Long
   
    iGroupId                As Long
   
    stateMask               As Long
    State                   As Long
    uAlign                  As Long
    ' IF >= WinVista
    pszSubtitle            As Long
    cchSubtitle            As Long
    pszTask                As Long
    cchTask                As Long
    pszDescriptionTop      As Long
    cchDescriptionTop      As Long
    pszDescriptionBottom   As Long
    cchDescriptionBottom   As Long
    iTitleImage            As Long
    iExtendedImage         As Long
    iFirstItem             As Long     ' Read only
    cItems                 As Long     ' Read only
    pszSubsetTitle         As Long   ' NULL if group is not subset
    cchSubsetTitle         As Long
End Type

Código: [Seleccionar]
Public Property Get GroupHeaderText(ByVal GroupID As Long) As String
    'EDITED BY CHIP! - FIXED GET TEXT POINTERS - ADDED LVGROUP_LP DATA TYPE
   
    If m_hListView Then
               
                Dim tLVG    As LVGROUP_lp
                Dim sBuffer As String
       
                sBuffer = Space$(260)
               
                With tLVG
                    .cbSize = Len(tLVG)
                    .mask = LVGF_HEADER
                    .cchHeader = 260
                    .pszHeader = StrPtr(sBuffer)
                End With
               
                If SendMessage(m_hListView, LVM_GETGROUPINFO, GroupID, tLVG) <> -1 Then GroupHeaderText = CopyString(ByVal tLVG.pszHeader, True)
               
    End If

End Property

Private Function CopyString(ByVal inPtr As Long, _
    Optional ByVal inAsWide As Boolean = False) As String
    Dim BufLen As Long
    If (inAsWide) Then
        BufLen = lstrlenW(inPtr)
        If (BufLen > 0) Then
            CopyString = Space$(BufLen)
            Call lstrcpyW(ByVal StrPtr(CopyString), inPtr)
        End If
    Else
        BufLen = lstrlenA(inPtr)
        If (BufLen > 0) Then
            CopyString = Space$(BufLen)
            Call lstrcpyA(CopyString, inPtr)
        End If
    End If
End Function

Note, you do not need the CopyString function, but I have included it for reference. If you do not wish to include the function, then you can copy the Pointer to the String using:  lstrcpyW  (in cases that are not Unicode, then you would use lstrcpyA).

Here is a slightly optimized Let GroupHeaderText( that uses StrPtr() instead of the StrConv().

Código: [Seleccionar]
Public Property Let GroupHeaderText(ByVal GroupID As Long, newText As String)

    If m_hListView Then
        Dim group As LVGROUP_lp

        With group
            .cbSize = Len(group)
            .mask = LVGF_HEADER
            .pszHeader = StrPtr(newText)
            .cchHeader = Len(.pszHeader)
        End With
        Call SendMessage(m_hListView, LVM_SETGROUPINFO, GroupID, group)
       
    End If
   
End Property



Finally, I will have an updated version of my FilterItems() that includes support for filtering WHILE they groups are displayed (very cool), both Windows Vista/7 & Windows XP.

Thanks guys!



11
Visual Basic 6 / Re:ucListViewEx 2.5 + clsIconList [UPDATED]
« en: Mayo 29, 2011, 08:55:05 pm »
greetings again. 

Here is the work I have done to modify this ucListview to fit my needs (basic theme-aware ListView with Sort and Filter)

new:
FilterItems (works both WinXP + Vista/7)
FilterEnabled (bool property)
FreezePaint (use before/after large updates to ListView)
DoubleBuffer style (reduces flicker when resizing, moving, adding, etc:  http://www.codeproject.com/KB/list/listviewxp.aspx)

minor:
removed 'force admin' from the manifest file for the compiled .exe
fixed backgroundimage bugs (clears BackGroundImage and also proper loading of images in the example)

http://www.convivea.com/download/ucListView2.5.chip.rar


let me know.

thanks,
chip



12
Visual Basic 6 / Re:ucListViewEx 2.5 + clsIconList [UPDATED]
« en: Mayo 27, 2011, 03:39:02 am »
Sorting of Columns when in Group Mode on Windows XP does not work.


EDIT:   this does not work on Windows XP  Service Pack 2, but it does work for Service Pack 3.

13
Visual Basic 6 / Re:ucListViewEx 2.5 + clsIconList [UPDATED]
« en: Mayo 27, 2011, 02:19:16 am »
To answer my question above...   

Using "Groups" to hide items works beautifully on Windows 7, but does not work on WinXP.

14
Visual Basic 6 / Re:ucListViewEx 2.5 + clsIconList [UPDATED]
« en: Mayo 26, 2011, 08:45:59 pm »
WinXP only shows Group without Substitle,Footer and collapse button. That means you can't collapse the groups. In Vista/Win7,the looking is better than ever.

Thanks Jen. So if I only want to use the groups to filter/hide list items as raul338 has suggested, "set 1 to the "visible" items and -1 to "not visible" items", would that require collapsing?  I wouldnt be home for a couple more hours to try this out. :)

15
Visual Basic 6 / Re:ucListViewEx 2.5 + clsIconList [UPDATED]
« en: Mayo 26, 2011, 05:59:41 pm »
Thanks for the suggestion, I will try that when I get home tonight.

Should that work on WinXP too or is that ListView "group feature" only available in Windows 7 (or Vista)?

Páginas: [1] 2