Jump to content

Listview row count


Recommended Posts

Is there a quick style, attribute, function I can use to add the row count on a listview?

I could have sworn I saw this before and I just can't find it. I don't want to have to add another column and inject the row numbers which will force me to change around some code that looks for the column. Something like the header, but row count instead.

Link to comment
Share on other sites

No, that gets the total count. I want to pretty much insert a third column...rather a first column...that shows the row number without actually changing the column count. Like a vertical header of sorts, like how you have the header/title, but it doesn't actually count as a row.

Edited by Champak
Link to comment
Share on other sites

Grab current selected row, append it's row number to the title (header) via:

_GUICtrlListView_SetColumn

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

But that would be changing the column count won't it? (I'm not at home to test it out) which I wouldn't want to do because I would have to go and change around a bunch of other code.

Just to clarify once again...only because I just thought of this and it made more sense to me...I want my first column to be just like excel. The row count is there, but it doesn't count as an actual column.

But it's looking like it isn't possible.

Link to comment
Share on other sites

I want my first column to be just like excel. The row count is there, but it doesn't count as an actual column.

I don't have this in my excel...

Try this :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>

Local $hGUI = GUICreate("MyGUI")

Global $_iLw1 = GUICtrlCreateListView("Col1", 10, 10, 200, 200)

_GUICtrlListView_SetColumnWidth(GUICtrlGetHandle($_iLw1), 0, 80)

Local $iBtnAdd = GUICtrlCreateButton("Add", 10, 220, 80, 22)

Local $iBtnDel = GUICtrlCreateButton("Delete", 100, 220, 80, 22)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

For $i = 1 To 10
    _LwAddItem()
Next

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $iBtnAdd
            _LwAddItem()
        Case $iBtnDel
            _LwDelItem()
    EndSwitch
WEnd

GUIDelete()

Func _LwAddItem()
    GUICtrlCreateListViewItem(Chr(Random(65, 90, 1)), $_iLw1)
EndFunc

Func _LwDelItem()
    _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($_iLw1))
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)

    Local $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    Local $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    Local $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $iIDFrom
        Case $_iLw1
            Switch $iCode
                Case $LVN_INSERTITEM
                    _GUICtrlListView_SetColumn($hWndFrom, 0, "Col1 (" & _GUICtrlListView_GetItemCount($hWndFrom) & ")")
                Case $LVN_DELETEITEM
                    _GUICtrlListView_SetColumn($hWndFrom, 0, "Col1 (" & (_GUICtrlListView_GetItemCount($hWndFrom) -1) & ")")
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc
Link to comment
Share on other sites

OK, i see what both of you are trying to do now. Thats not what im trying to do. I need to see each row count/indices, like this excel pic. But I didnt want to add a column. I thought I saw it before without having to actually create a column and cycle through the list and input the number...like it was automatic.

post-12133-0-19953600-1393872585_thumb.p

Link to comment
Share on other sites

  • Moderators

Champak,

You have UEZ to thank for this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

Global Const $iMax = 40

Global $iPos_1 = 0, $iPos_2 = 0

$hGUI = GUICreate("Synchro Pair", 195, 240, -1, -1)
$cLV_2 = GUICtrlCreateListView("Items", 60, 5, 85, 220)
$hLV_2 = GUICtrlGetHandle($cLV_2)
GUISetState(@SW_SHOW)

$hGUI_Child = GUICreate("", 50, 220, 10, 5, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
$cLV_1 = GUICtrlCreateListView("Index", 0, 0, 85, 220)
$hLV_1 = GUICtrlGetHandle($cLV_1)
GUISetState()

For $i = 1 To $iMax
    GUICtrlCreateListViewItem($i, $cLV_1)
    GUICtrlCreateListViewItem("Item " & $i, $cLV_2)
Next

Global $aRect = _GUICtrlListView_GetItemRect($hLV_2, 0)
Global Const $iDeltaY = $aRect[3] - $aRect[1]
GUIRegisterMsg($WM_NOTIFY, "_WM_Notify")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _WM_Notify($hWnd, $Msg, $wParam, $lParam)
    Local Const $iLines = _SendMessage($hLV_2, $LVM_GETTOPINDEX) - _SendMessage($hLV_1, $LVM_GETTOPINDEX)
    _SendMessage($hLV_1, $LVM_SCROLL, 0, $iLines * $iDeltaY)
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>_WM_Notify
You should be able to integrate that into your code - let me know if you need a hand. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks. That's an interesting way to do it. I'm unable to try it now, but by looking at it, instead of creating a child GUI, why wouldn't someone just make two listview controls and then use the message notify to highlight or duplicate the actions of the "partner" listview on the same indices of the other "partner" listview? Is there a reason a child GUI was used that I'm not seeing.

Dw1, I just never used that before.

Edited by Champak
Link to comment
Share on other sites

  • Moderators

Champak,

 

Is there a reason a child GUI was used that I'm not seeing

It prevents the scrollbar displaying in the "Index" ListView when it appears- that bit was my contribution to the script. ;)

M23

Edit:

FireFox,

:thumbsup:

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...