Jump to content

refresh combobox


Recommended Posts

I have following code

#cs ----------------------------------------------------------------------------
 AutoIt Version: 3.1.1.0
 Author:         Steven Vandenhoute
 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------
; Script Start - Add your code below here
#include <GUIConstants.au3>
FileInstall("P&F 27.ico", "P&F 27.ico",1)
#NoTrayIcon
Dim $server

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\b00b27\Desktop\printerutility\form1.kxf
$Form1 = GUICreate("Network Printer Utility", 269, 135, 193, 115)
GUISetFont(8, 400, 0, "Comic Sans MS")
$Icon1 = GUICtrlCreateIcon("P&F 27.ico",0, 16, 16, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP))
$Label1 = GUICtrlCreateLabel("NPU", 16, 48, 43, 31)
GUICtrlSetFont(-1, 14, 800, 0, "Comic Sans MS")
$Combo1 = GUICtrlCreateCombo("", 80, 20, 185, 25)
GUICtrlSetData($Combo1, "server1|server2|server3")
GUICtrlSetFont(-1, 8, 400, 0, "Comic Sans MS")
$Combo2 = GUICtrlCreateCombo("", 80, 50, 185, 25)
GUICtrlSetFont(-1, 8, 400, 0, "Comic Sans MS")
$Button2 = GUICtrlCreateButton("Install", 48, 100, 90, 25, 0)
GUICtrlSetFont(-1, 8, 400, 0, "Comic Sans MS")
$Button1 = GUICtrlCreateButton("Exit", 168, 100, 90, 25, 0)
GUICtrlSetFont(-1, 8, 400, 0, "Comic Sans MS")

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $Msg = GUIGetMsg()
        Select
        Case $msg=$GUI_EVENT_CLOSE or $msg=$Button1
            ExitLoop
    
    
        Case $msg = $Combo1
            $server=GUICtrlRead($Combo1)
            if $server="server1" Then
                GUICtrlSetData($Combo2, "printer1|printer2|printer3")
            ElseIf $server="server2" Then
                GUICtrlSetData($Combo2, "printer4|printer5|printer6")
            Else
                GUICtrlSetData($Combo2, "printer7|printer8|printer9")
                        
                    EndIf
                    
                case $msg=$Button2




if GUICtrlRead($Combo1)="" or GUICtrlRead($Combo2)="" Then
    MsgBox(0,"ERROR", "Please select Server and printer")
Else
    
_addprinter()

EndIf



    EndSelect
WEnd



Func _addprinter()

$url="\\"& $server &"\"&GUICtrlRead($Combo2)
RunWait("rundll32 printui.dll,PrintUIEntry /in /q /n" & $url)



EndFunc

Problem is, when I chose one server, and I want to chose another server without closing the program, the list with printers don't refresh.

How can I fix this?

"You cannot solve a problem with the mind that created it" (Albert Einstein)

Link to comment
Share on other sites

I have following code

<snip>

Problem is, when I chose one server, and I want to chose another server without closing the program, the list with printers don't refresh.

How do you know ? What testing have you done to make sure that theright code-lines have been executed ?

Personally I have two problems with your code :

1) both drop-down boxes are just 25 pixels high, leaving, on my OS (W98) no room for the drop-down part of the box (containing the names of the servers and printers). Add something like 90 pixels so you can see at least 3 items before getting a scroll-bar

2) When you select another server the new printers seem to be added (in the second combo-box) to the allready existing ones. Something that became very clear when I renamed the printers to "Srv1Prn1", "Srv1Prn2", etc.

In short : first clear the combo-box, than put the new printers into it.

Hope that helps

[edit]

I see you allready found the problem :-)

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