Sign in to follow this  
Followers 0
muncherw

Refreshing a Combo Box

7 posts in this topic

#1 ·  Posted (edited)

At work we have a lot of servers with a few key folders I map to a lot. I thought making a program to map directly where I wanted would be easier than constantly mapping them manually. Currently I have an input box that asks me which letter I want to map to but i'd like to make that a little nicer. I know how to do this (currently not programmed) with a combo box I have ut I don't know how to refresh the combo box.

 

I am scanning to see what drives are mapped and I create a combo box that lists them. I want people to be able to choose them and unmap or re-map to those letters. I can do that fine, however once I connect a new drive or disconnect an existing drive I'd like the combo box to be updated. I can get the new information no problem. It's all about refreshing the combo box with that info that befuddles me.

 

I didn't find anything in the forums. I thought maybe I could use _GUICtrlComboBoxEx_ResetContent or something like that but that doesn't do what I want (or I don't know how to make it work properly.

 

Any help would be appreciated.

Thank you,

Muncher

 

 

 

This is how I get my drives:

 

 

$list = ""
For $i = Asc("I") to Asc("Z")
    $drive = Chr($i) & ":"
    $list = $list & $drive & " " & DriveMapGet($drive) & "|"
    $DriveName = $drive &  DriveMapGet($drive)
;MsgBox(4096,"Drive is mpped to", $DriveName)
Next

 

This is my combo box:

 

 

$combo = GuiCtrlCreateCombo("Select a Drive",30, 75, 220, 200)
$DriveLettersList = StringLeft($list,StringInStr($list,":"));the first drive letter
GuiCtrlSetData($combo, $list)

 

 

Below is the full code if you want to see what I'm talking about in it's environment.

#include <GUIConstants.au3>

#include <Array.au3>





Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase



$myProg = "Busey Server Mapper"

;Looks to see it the program is already open so

If WinExists($myProg) Then

WinActivate("Busey Server Mapper")

Exit ; It's already running

endif



AutoItWinSetTitle($myProg)





$list = ""

For $i = Asc("I") to Asc("Z")

$drive = Chr($i) & ":"

$list = $list & $drive & " " & DriveMapGet($drive) & "|"

$DriveName = $drive & DriveMapGet($drive)

;MsgBox(4096,"Drive is mpped to", $DriveName)

Next





;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5





;*******************Begining of GUI***********************

$dlgTabbed = GUICreate("Busey Server Mapper", 400, 149, 193, 120)

$PageControl1 = GUICtrlCreateTab(15, 8, 255, 55)

;GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)



$radioVol1 = GUICtrlCreateRadio("Vol1_share", 300, 15, 113, 17)

$radioApps = GUICtrlCreateRadio("apps_share", 300, 35, 113, 17)

$radioGroup = GUICtrlCreateRadio("group_share", 300, 55, 113, 17)

$radioUsers = GUICtrlCreateRadio("users_share", 300, 75, 113, 17)

GUICtrlSetState(-1,$GUI_CHECKED) ;Default users_share to being checked



$mapDrive = GUICtrlCreateButton("Map Drive", 20, 118, 75, 25)

$unmapDrive = GUICtrlCreateButton("UnMap Drive", 110, 118, 75, 25)

$Ping = GUICtrlCreateButton("Ping Server", 200, 118, 75, 25)

$EXIT = GUICtrlCreateButton("Close", 290, 118, 75, 25)





;Champaign Tab

$ChampTab = GUICtrlCreateTabItem("Champaign")

GUICtrlSetState(-1,$GUI_SHOW) ;Sets this tab as the default one to show

$ChampDropdown = GUICtrlCreateCombo("NONE", 30, 33, 220, 25)

GUICtrlSetData(-1, "Champaign- 303 Kirby|Champaign- 909 Kirby|Champaign- Campus|Champaign- Executive Center|Champaign- Fox Drive|Champaign- Fox Drive- Ops|Champaign- Fox Drive- 2302|Champaign- Marketview|Champaign- SPC|Champaign- SPR|Champaign- University|Champaign- Windsor|Gibson City|Indianapolis|LeRoy- Cedar|Mahomet- Main|Paxton|Rantoul- Grove|Rantoul- Sangamon|St Joseph|Savoy- Arbors|Thomasboro|Tolono- Holden|Urbana- Main Bank|Urbana- Pines|Urbana- Sunnycrest")

GUICtrlSetFont(-1, 8, 400, 0, "Arial")



;Macon Tab

$MaconTab = GUICtrlCreateTabItem("Macon")

$Macondropdown = GUICtrlCreateCombo("NONE", 30, 33, 220, 25)

GUICtrlSetData(-1, "Decatur- Ash|Decatur- First Plaza|Decatur- Main|Decatur- MLK|Decatur- North (Water)|Decatur- Park|Fairbury|Mt Zion- Plaza|Mt Zion- Main|Shelbyville- Main|Shelbyville- West (County Market)")

GUICtrlSetFont(-1, 8, 400, 0, "Arial")



;Mclean Tab

$McleanTab = GUICtrlCreateTabItem("McLean")

$McleanDropdown = GUICtrlCreateCombo("NONE", 30, 33, 220, 25)

GUICtrlSetData(-1, "Bloomington- Eastland|Bloomington- East Washington|Bloomington- Fairway|Bloomington- Hamilton|Bloomington- Parkway|Bloomington- Veterans|Normal- Fort Jesse|Normal- College")

GUICtrlSetFont(-1, 8, 400, 0, "Arial")



;Peoria Tab

$PeoriaTab = GUICtrlCreateTabItem("Peoria")

$PeoriaDropdown = GUICtrlCreateCombo("NONE", 30, 33, 220, 25)

GUICtrlSetData(-1, "East Peoria|Pekin|Peoria- Adams|Peoria- Kumpf|Peoria- Sheridan|Peoria- Grand Prairie")

GUICtrlSetFont(-1, 8, 400, 0, "Arial")



;Florida Tab

$FloridaTab = GUICtrlCreateTabItem("Florida")

$FloridaDropdown = GUICtrlCreateCombo("NONE", 30, 33, 220, 25)

GUICtrlSetData(-1, "Cape Coral- Del Prado|Cape Coral- Parkway|Cape Coral- Santa Barbara|Englewood|Ft Myers- Cypress Terrace|Ft Myers- San Carlos|Ft Myers- Summerlin|North Port|Port Charlotte- Murdock|Port Charlotte- Ops|Punta Gorda")

GUICtrlSetFont(-1, 8, 400, 0, "Arial")



GUICtrlCreateTabItem("")



GUISetState(@SW_SHOW)





$combo = GuiCtrlCreateCombo("Select a Drive",30, 75, 220, 200)

$DriveLettersList = StringLeft($list,StringInStr($list,":"));the first drive letter

GuiCtrlSetData($combo, $list)











;****************************End of GUI ********************************







While 1



$id = _getBOX()



Select

; Champaign Location

Case GUICtrlRead($id) = "Champaign- 303 Kirby"

$server = "svrchamp303"



; Cases removed because they aren't relevant to the question and it

; is a long list







EndSelect





Switch GUIGetMsg()

;************************** The Map Drive button was clicked *******************

Case $mapDrive



$driveLetter = InputBox("Get Drive", "Enter Drive letter you want to map to:", "")



;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

;If they click cancel some error checking needs to happen

;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&





$driveLetter = $driveLetter & ":"



If WinExists($driveLetter) Then

WinClose($driveLetter)

WinWaitClose($driveLetter)

Endif



$id = _getBOX()

;MsgBox(1, "ComboBox controlID: " & $id, GUICtrlRead($id) & " was selected.")



If IsChecked($radioVol1) Then

$folder = "vol1_share"

ElseIf IsChecked($radioApps) Then

$folder = "apps_share"

ElseIf IsChecked($radioGroup) Then

$folder = "group_share"

ElseIf IsChecked($radioUsers) Then

$folder = "users_share"

EndIf



; Check to see if the drive they are mapping to is already mapped.

; If it is then delete the mapping

; Possibly change this to ask if they want to map to a different drive



While 1



Sleep(500)

DriveMapGet($driveLetter)

If @Error = 1 then

;MsgBox(4096, "Test", "No drive mapped. Exiting loop.", 10)

ExitLoop

else

;MsgBox(0, "Drive P: is mapped to", DriveMapGet($driveLetter) & ". We need to unmap it.")

DriveMapDel($driveLetter)

Sleep(500)

endIf

Wend





If GUICtrlRead($id) = "NONE" Then

MsgBox(0, "No Server Selected", "Please choose a server and try to map again. ")

ElseIf GUICtrlRead($id) = "Shelbyville- West (County Market)" Then

MsgBox(0, "Shelbyville, really?", "Yeah, I don't think so. You'll be waiting for a week just to get connected. /n Pick a different server because I refuse to map to this one.")

Else

DriveMapAdd($driveLetter, "\\" & $server & "\" & $folder)

_waitDriveMap()

Run('c:\windows\explorer.exe ' & $driveLetter & '\')

EndIf





Case $unmapDrive





Select

Case $result = "I"

Case $result = "J"

Case $result = "K"

Case $result = "L"

Case $result = "M"

Case $result = "N"

Case $result = "O"

Case $result = "P"

Case $result = "Q"

Case $result = "R"

Case $result = "S"

Case $result = "T"

Case $result = "U"

Case $result = "V"

Case $result = "W"

Case $result = "X"

Case $result = "Y"

Case $result = "Z"

EndSelect





;********************** The Ping button was clicked ******************

Case $Ping

$id = _getBOX()

If GUICtrlRead($id) = "NONE" Then

MsgBox(0, "No Server Selected", "Please choose a server and try your ping again. ")

Else

RunWait(@COMSPEC & " /k ping " & $server & " /t" , @WorkingDir)

EndIf



;*********** The Close button was clicked ***************************

Case $GUI_EVENT_CLOSE, $EXIT

ExitLoop



EndSwitch



Wend





; Checks to see which dropdown is selected

Func _getBOX()

Switch GUICtrlRead($PageControl1)

Case 0 ;Champaign

$box = $ChampDropdown

Case 1 ;Macon

$box = $Macondropdown

Case 2 ;Mclean

$box = $McleanDropdown

Case 3 ;Peoria

$box = $PeoriaDropdown

Case 4 ;Florida

$box = $FloridaDropdown

EndSwitch

Return $box

EndFunc





; Checks to see if the radio button is checked

Func IsChecked($control)

Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED

EndFunc





;Checks to see if the drive has been mapped

Func _waitDriveMap()

While 1

DriveMapGet($driveLetter)

If @Error = 1 then

MsgBox(0, "Drive isn't mapped. Let's try again.")

Sleep(500)

else

;MsgBox(0, "Success!!", DriveMapGet($driveLetter) & ".")

ExitLoop

endIf

Wend

EndFunc









Func _GetFreeDriveLetters()

Dim $aArray[1]

For $x = 69 To 90 ;E through Z

If DriveStatus(Chr($x) & ':\') = 'INVALID' Then

ReDim $aArray[uBound($aArray) + 1]

$aArray[uBound($aArray) - 1] = Chr($x) & ':'

EndIf

Next

$aArray[0] = UBound($aArray) - 1

Return($aArray)

EndFunc

 

Edited by Jon
Broken code box

Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]

Share this post


Link to post
Share on other sites



$list = ""
For $i = Asc("I") to Asc("Z")
    $drive = Chr($i) & ":"
    $list = $list & $drive & " " & DriveMapGet($drive) & "|"
    $DriveName = $drive &  DriveMapGet($drive)
;MsgBox(4096,"Drive is mpped to", $DriveName)
Next
Change this to

$list = ""
For $i = Asc("I") to Asc("Z")
    $drive = Chr($i) & ":"
    $list &= "|" & $drive & " " & DriveMapGet($drive)
    $DriveName = $drive &  DriveMapGet($drive)
;MsgBox(4096,"Drive is mpped to", $DriveName)
Next

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Thanks for the quick reply GeoSoft. This part actually functions perfectly for me. My problem is more getting this information to overwrite a combo box that already exists.


Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]

Share this post


Link to post
Share on other sites

Thanks for the quick reply GeoSoft. This part actually functions perfectly for me. My problem is more getting this information to overwrite a combo box that already exists.

Just use GuiCtrlSetData($your_combo, "") before setting your values.

Share this post


Link to post
Share on other sites

Just use GuiCtrlSetData($your_combo, "") before setting your values.

I am using that when I initially create the gui. I guess I'm confused at to what you're suggesting. Can you elaborate?


Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]

Share this post


Link to post
Share on other sites

Thanks for the quick reply GeoSoft. This part actually functions perfectly for me. My problem is more getting this information to overwrite a combo box that already exists.

That's why I moved the "|" to the begining of the line. That will empty the current contents and set the new data

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

That's why I moved the "|" to the begining of the line. That will empty the current contents and set the new data

Oooooh. I thought you misunderstood what I was saying. I didn't realize that the seperator at the beggining made any difference. I made that change and a small change to the code and that worked perfectly. Thanks very much. Sorry I dismissed that at first, I just didn't get what you were telling me or why. I really appreciate this, GEOSoft.


Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]

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