Melf123

GUICtrlCreateListView issue for getting subitem value

7 posts in this topic

Hi there, i just started coding in autoit and ive been stuck on this for a wile now...I have a listview and when a row is selected and the remove button is pressed i want to get the value of the last subitem which contains the pricing ( last column). I want to remove the value from the total and display the result to the same inputbox in the form. How can I do that? here's what i tought might work but dosent :

$List1 = GUICtrlCreateListView("Quantity|Items|Pricing", 424, 104, 297, 370,($LVS_SORTASCENDING))

Func remove()
   $e =  _GUICtrlListView_GetItem($List1, 2);i want the value stored in subitem pricing in the row selected
   $b = GUICtrlRead($Total)
   $z = Execute("($b-$e)")
   GUICtrlSetData($Total, $e)
   _GUICtrlListView_DeleteItemsSelected($list1)   
EndFunc

any feed back would be greatly appreciated thank you

Share this post


Link to post
Share on other sites



Melf123,

Welcome to the AutoIt forums. :)

This should give you an idea of how you might go about it: ;)

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

$hGUI = GUICreate("Test", 500, 500)

$cListView = GUICtrlCreateListView("Quantity|Items|Pricing", 10, 10, 400, 370, bitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL, $LVS_SORTASCENDING))
For $i = 0 To 9
    GUICtrlCreateListViewItem($i & "|Item " & $i & "|" & $i & ".99", $cListView)
Next

$cInput = GUICtrlCreateInput("0", 10, 400, 200, 20)

$cRemove = GUICtrlCreateButton("Remove", 10, 450, 80, 30)

GUISetState()

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

Func _Remove()

    ; Get date from currntly selected item
    $aData = _GUICtrlListView_GetItemTextArray($cListView)
    ; Read current value in input
    $nTotal = Number(GUICtrlRead($cInput))
    ; Put new price in input
    GUICtrlSetData($cInput,$nTotal + Number($aData[3]))
    ; Delete item
    $cID = GUICtrlRead($cListView)
    GUICtrlDelete($cID)

EndFunc
Please ask if anything is unclear. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Melf,

The more the merrier...

Another way...

#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>

local $gui010 = guicreate('')
$List1 = GUICtrlCreateListView("Quantity|Items|Pricing", 10,10,200,200,($LVS_SORTASCENDING))
$total = guictrlcreatelabel('',230,20,100,20,$ss_sunken)
local $btn010 = guictrlcreatebutton('Delete Total in Selected Item',10, 250, 380, 20)
guisetstate()

for $1 = 1 to 20
    guictrlcreatelistviewitem(random(1,9,1) & '|' & chr(random(65,90,1)) & '|' &  stringformat('%2.2f',random(100,999)), $list1)
next

while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
        case $btn010
            remove()
    EndSwitch
WEnd

Func remove()

    guictrlsetdata($total, guictrlread($total) + _GUICtrlListView_GetItemText ( $list1, _GUICtrlListView_GetSelectedIndices ( $list1, true)[1] , 2))
    _GUICtrlListView_SetItem($list1, "", _GUICtrlListView_GetSelectedIndices ( $list1, true)[1], 2 )

EndFunc

edit: removed the @CRLF

Edited by 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

Melf123,

This example is better.  It handles multiple selections...

#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>

local $gui010 = guicreate('Listview Sub-item Example',400, 350)
$List1 = GUICtrlCreateListView("Quantity|Items|Pricing", 10,10,180,250,($LVS_SORTASCENDING))
guictrlcreatelabel('Total',230,20,100,20)
$total = guictrlcreatelabel('',230,40,100,20,$ss_sunken)
local $btn010 = guictrlcreatebutton('Delete Price in Selected Item and add to Total',10, 320, 380, 20)
guisetstate()

for $1 = 1 to 20
    guictrlcreatelistviewitem(random(1,9,1) & '|' & chr(random(65,90,1)) & '|' &  stringformat('%2.2f',random(100,999)), $list1)
next

while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
        case $btn010
            remove()
    EndSwitch
WEnd

Func remove()

    local $aSel = _GUICtrlListView_GetSelectedIndices ( $list1, true )  ;   get array of selected items
    if $aSel[0] = 0 then return ;   nothing selected, return

    ; add each selected item to total then delete the price column
    for $1 = 1 to $aSel[0]
        guictrlsetdata($total, guictrlread($total) + _GUICtrlListView_GetItemText ( $list1, $aSel[$1] , 2))
        _GUICtrlListView_SetItem($list1, "", $aSel[$1], 2 )
    next

EndFunc

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

Hmm for some reason the total aint good with multiple selects more then 5, and i want the entire selected row to dissapear not just the pricing

Share this post


Link to post
Share on other sites

See M23's code for deleting the row...check my code for multiple selections...


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