Jump to content
Sign in to follow this  
langthang084

Get number of Item in the column of ListView?

Recommended Posts

langthang084

I create the ListView with 3 columns. Each Column has diffirent number of items. 

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

    Local $idListview

    GUICreate("ListView Get Item Text Array", 400, 300)

    $idListview = GUICtrlCreateListView("col1|col2|col3", 2, 2, 394, 268)
    GUICtrlCreateListViewItem("line1|data1|more1", $idListview)
    GUICtrlCreateListViewItem("line2|data2|more2", $idListview)
    GUICtrlCreateListViewItem("line3|data3|more3", $idListview)
    GUICtrlCreateListViewItem("line4|data4", $idListview)
    GUICtrlCreateListViewItem("line5|", $idListview)

    GUISetState(@SW_SHOW)


    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()

I used _GUICtrlListView_GetItemCount but it dont get on each Column

:(:(:(

Share this post


Link to post
Share on other sites
langthang084

And how to autoscroll to the last item of each columns? (example: when I input data by columns)

Share this post


Link to post
Share on other sites
Malkey

This example should give you some ideas.

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

Local $idListview

Local $hWin = GUICreate("ListView Get Item Text Array", 400, 300)

$idListview = GUICtrlCreateListView("col1|col2|col3", 2, 2, 394, 268)
GUICtrlCreateListViewItem("line1|data1|more1", $idListview)
GUICtrlCreateListViewItem("line2|data2|more2", $idListview)
GUICtrlCreateListViewItem("line3|data3|more3", $idListview)
GUICtrlCreateListViewItem("line4|data4", $idListview)
GUICtrlCreateListViewItem("line5", $idListview)
For $y = 6 To 30
    GUICtrlCreateListViewItem("line" & $y, $idListview)
Next
GUISetState(@SW_SHOW)

Local $aArray[_GUICtrlListView_GetItemCount($idListview) + 1][_GUICtrlListView_GetColumnCount($idListview)]
For $i = 0 To UBound($aArray) - 2
    For $j = 0 To UBound($aArray, 2) - 1
        $aArray[$i + 1][$j] = _GUICtrlListView_GetItem($idListview, $i, $j)[3]
        If $aArray[$i + 1][$j] <> "" Then $aArray[0][$j] += 1
    Next
Next
_ArrayDisplay($aArray)

Local $hCtrl = ControlGetHandle($hWin, "", $idListview)
MsgBox($MB_SYSTEMMODAL, "Information", "Item count in Column#1 = " & $aArray[0][0] & @LF & _
        "Item count in Column#2 = " & $aArray[0][1] & @LF & _
        "Item count in Column#3 = " & $aArray[0][2], 0, $hCtrl)

_GUICtrlListView_Scroll($idListview, _GUICtrlListView_GetItemPositionX($idListview, 0), _GUICtrlListView_GetItemPositionY($idListview, $aArray[0][0] - 1))
MsgBox(0, "Wait", "View end of column 1", 0, $hCtrl)
_GUICtrlListView_Scroll($idListview, _GUICtrlListView_GetItemPositionX($idListview, 1), _GUICtrlListView_GetItemPositionY($idListview, $aArray[0][1] - 2))
MsgBox(0, "Wait", "View end of column 2", 0, $hCtrl)
_GUICtrlListView_Scroll($idListview, _GUICtrlListView_GetItemPositionX($idListview, 2), _GUICtrlListView_GetItemPositionY($idListview, $aArray[0][2] - 2))
MsgBox(0, "Wait", "View end of column 3", 0, $hCtrl)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

 

  • Like 1

Share this post


Link to post
Share on other sites
kylomas

==> Malkey,

Nice!   Why do you make the MsgBox's children of the listview control?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Malkey

@kylomas


At one stage I named the GUI window ($hWin) to use as the parent of MsgBox dialog.  This keeps the message box on top of the GUI.

I got side-tracked and became obsessed with "$idListview", which appears in a lot of the functions in the script.  Of course "$idListview" is an identifier (id).   But I needed a handle for the MsgBox parameter. So the focus on "$idListview" reached its logical conclusion.   Testing showed it worked, and I didn't think any more about it until your post.

Malkey

Share this post


Link to post
Share on other sites
kylomas

Thanks, just curious...


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
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
Sign in to follow this  

×