Melf123 Posted February 17, 2015 Posted February 17, 2015 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
Moderators Melba23 Posted February 17, 2015 Moderators Posted February 17, 2015 Melf123,Welcome to the AutoIt forums. This should give you an idea of how you might go about it: expandcollapse popup#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) EndFuncPlease 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
kylomas Posted February 17, 2015 Posted February 17, 2015 (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 February 17, 2015 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
kylomas Posted February 17, 2015 Posted February 17, 2015 Melf123, This example is better. It handles multiple selections... expandcollapse popup#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
Melf123 Posted February 18, 2015 Author Posted February 18, 2015 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
kylomas Posted February 18, 2015 Posted February 18, 2015 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now