Sign in to follow this  
Followers 0
Necromorph

Combobox refresh

7 posts in this topic

#1 ·  Posted (edited)

okay, here is what i need to do, i have a .txt with all the usernames i manage and assist. i _FileReadToArray() that for my combobox drop down, but i want to be able to delete a user out of there with a 'delete' button. and after that does that, i need it to 'refresh' the combobox drop down so the user is 'gone'. here is what i have:

Global $users = "C:\ProgramData\tmPCSolutions\Users.txt"
    $labelUserName = GUICtrlCreateLabel("user assisted", 200, 25)
    $comboUserName = GUICtrlCreateCombo("none", 200, 47.5, 150, -1, $CBS_DROPDOWNLIST)
        GUICtrlSetData($comboUserName, "none", default)
        Dim $displayUsers
            _FileReadToArray($users, $displayUsers)
            _ArraySort($displayUsers)
        For $varUsers = 1 to $displayUsers[0]
            GUICtrlSetData($comboUserName, $displayUsers[$varUsers])
        Next
        $buttonDeleteUser = GUICtrlCreateButton("delete user", 275, 75, 75)
While 1
     $msg = GUIGetMsg()
     Switch $msg
          Case $buttonDeleteUser
          If GUICtrlRead($comboUserName) = "none" Then
           MsgBox(48, "redLabel timeKeeper", "you cannot delete the 'none' entry!")
      Else
           $msgboxDeleteUser = MsgBox(36, "redLabel timeKeeper", "would you like to delete the selected user?" & @CRLF & "'" & GUICtrlRead($comboUserName) & "'")
                If $msgboxDeleteUser = 6 Then
                 ;==> i need code here to delete the selected user in the combobox, and refresh the userlist ;  
                    EndIf
      EndIf
     EndSwitch
Wend

i was think it needs to $newArray = _arraydelete($selectedUser) then $newUserlist = _arrayWriteToFile($newArray) then GUICtrlSetState($comboUsername, $newUserList), but this doens't quite happen like that.

thanks.

Edited by redLabel

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Is _GUICtrlComboBox_DeleteString what you need?

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

BTW this works with wmic.

Please be carefull with your accounts when using this script.

#RequireAdmin
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>
Dim $avarray
_FileReadToArray(@ScriptDir&"\users.txt",$avarray)
_ArraySort($avarray)

$Form1 = GUICreate("Form1", 398, 217, -1,-1)
$Combo1 = GUICtrlCreateCombo("", 96, 48, 185, 25, $CBS_DROPDOWNLIST)
For $i=1 To $avarray[0]
    GUICtrlSetData($Combo1,$avarray[$i])
    Next
$Button1 = GUICtrlCreateButton("Delete", 136, 152, 89, 25, $WS_GROUP)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1 ;deleting
RunWait("cmd.exe /c " & "net user " & GUICtrlRead($Combo1) & " /delete",@ScriptDir,@SW_HIDE)

RunWait("cmd.exe /c " & "wmic USERACCOUNT get Name >"&@ScriptDir&"\users.txt",@ScriptDir,@SW_HIDE)

_FileReadToArray(@ScriptDir&"\users.txt",$avarray)
GUICtrlSetData($Combo1,"")
For $i=2 To $avarray[0]
GUICtrlSetData($Combo1,$avarray[$i])
    Next
    MsgBox(64,"Complete","Complete",10)

    EndSwitch
WEnd

[size="5"] [/size]

Share this post


Link to post
Share on other sites

thank you much for you reply's i have been working with the GUICtrlComboBox_DeleteString() func, but im running into problems, i am storing the users in a .txt file and then reading from it to populate the combobox array, then i need to delete an entry from it, open the file, erase it's contents, then rewrite the new array (without the deleted user), and then close it. and i just can't get it to work, im wondering if there is another way, or place to keep my "users" inplace of a .txt file. thanks for all the help.

#include <GUIConstantsEx.au3>
#include <GUIComboBoxEx.au3>
#include <ComboConstants.au3>
#include <Array.au3>
#include <file.au3>

GUICreate("", -1, -1)
GUISetState()
$comboUserNames = GUICtrlCreateCombo('none', 25, 25, 150, -1, $CBS_DROPDOWNLIST)
$handleUserNames = GUICtrlGetHandle($comboUserNames)
GUICtrlSetData(-1, 'none', Default)
$users = "C:\ProgramData\tmPCSolutions\Users - Copy.txt"
Dim $userList
_FileReadToArray($users, $userList)
_ArraySort($userList)
For $varUsers = 1 To $userList[0]
    GUICtrlSetData($comboUserNames, $userList[$varUsers])
Next
$buttonDeleteUser = GUICtrlCreateButton("delete user", 25, 75, 75)
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $buttonDeleteUser
            $varDeletedUser = _GUICtrlComboBox_SelectString($handleUserNames, GUICtrlRead($comboUserNames))
            _GUICtrlComboBox_DeleteString($handleUserNames, $varDeletedUser)
            $varNewArray = _GUICtrlComboBoxEx_GetListArray($handleUserNames)
            $varNewUserArray = _ArrayDelete($varNewArray, 'none' & _ArrayMin($varNewArray))
            _FileWriteFromArray($users, $varNewUserArray)
            FileClose($users)
            GUICtrlSetData($comboUserNames, 'none')
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

i got it to work somewhat, like this:

If $msgboxDeleteUser = 6 Then
                    $varDeletedUser = _GUICtrlComboBox_SelectString($handleUserName, GUICtrlRead($comboUserName))
                    _GUICtrlComboBox_DeleteString($handleUserName, $varDeletedUser)
                    GUICtrlSetData($comboUserName, 'none')
                    $newUserList = _GUICtrlComboBox_GetListArray($handleUserName)
                    _ArrayDelete($newUserList, 0 & 1)
                    FileOpen($users, 2)
                    _FileWriteFromArray($users, $newUserList, 1)
                    FileClose($users)
                EndIf

Share this post


Link to post
Share on other sites

I had same problem, but answer was way simpler than that..... 

Delete the combo box, recreate it, reload data, and then SETSTATE

User will never see you updated the list.

I used a SQL Query, rather than the file, but the answer is the same.

GUICtrlDelete($Entity)
$Entity = GUICtrlCreateCombo("Select CountID", 10, 10, 200)
GUISetState()
 
$sql  = " SELECT  ";
$sql &= "   Location ";
$sql &= " , CountID  ";
$sql &= " FROM  ";
$sql &= "   PHYSINV  ";
$sql &= " WHERE  ";
$sql &= "   CreateDate > '" & _DateAdd('D', -41, @YEAR & "/" & @MON & "/" & @MDAY ) & "' ";
$rs = $sqlCon.Execute($sql);
$rs.MoveFirst() ; move to the first record
Do
$p = $rs.getRows(1) ; get next row
GUICtrlSetData($Entity, $p[0][1] & ' [' & $p[0][0] & ']' ) ; load entities in window from database.
Until $rs.EOF ; until no more rows
GUISetState()

Share this post


Link to post
Share on other sites

jclent,

No need to delete and recreate the combo. Get the data into a delimited string and start the string with the delimiter - makes it easy to append items as you add them as you can prefix them all with the delimiter. ;)

From the Help file:

 

"For Combo or List control :

If the "data" corresponds to an already existing entry it is set as the default.

If the "data" starts with GUIDataSeparatorChar or is an empty string "" the previous list is destroyed"

Much cleaner that way. :)

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

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  
Followers 0