Jump to content
Sign in to follow this  
SmOke_N

Refreshing a combo box

Recommended Posts

SmOke_N

Hey all, I'm trying to get my combo box to refresh with new windows in it. When I click out of 1 and or another window is opened then to show that in the combo box.

$list = GUICtrlCreateCombo("", 5, 101, 390, 30)
Dim $x = 1
For $i = 1 To $var[0][0]
   If $var[$i][0] = "" Then ContinueLoop
   If IsVisible($var[$i][1]) Then
      $x = $x - 1
      GUICtrlSetData($list, $var[$i][0] & "|")
   EndIf
Next

Func IsVisible($handle)
   If BitAND( WinGetState($handle), 2) Then
      Return 1
   Else
      Return 0
   EndIf

Is it right under my nose and I'm not seeing it?

Thanks

¿RonsRules?


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
igmeou

Hi,

Just a question. Is these codes extract from my recent post regarding combobox??

If yes then, I should say that you should need to add some code to complete it. Preferably add an update function into the main loop.

Sorry, I had to go now. I get back to you when I'm back again.


[font="Arial"]Thanks[/font]
If @error = me Then $sorry
Else
   Do
      $clarifyMe
   Until $meClear
EndIF
MsgBox(0,"Special Message!","Special Thanks to " & $allHadReplied,$Forever)

Share this post


Link to post
Share on other sites
SmOke_N

Hi,

Just a question. Is these codes extract from my recent post regarding combobox??

If yes then,  I should say that you should need to add some code to complete it. Preferably add an update function into the main loop.

Sorry, I had to go now. I get back to you when I'm back again.

<{POST_SNAPBACK}>

Actually, this code was picked and pasted from some of CyberSlug suggestions Larrys, and it was really done from a Post about a month and a half ago, I even posted the links I believe in your post.

I had read your Post, tried your script (pretty neat by the way), but the window doesn't refresh, so it doesn't help me because i already had what i needed. I'm not calling a window to come up, i'm using it to GUIRead, and have another program do a function out of that window.

Edited by ronsrules

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
igmeou

Ok. I'm back. Now, I see. I ask that because if you are getting from my code then it would be easiler for me to help you out. Anyway, this is the amendment done to my code for it to update the combo box. But I think there would be a better way :)

Updated code from my post for your reference. Ops! I forgot to thanks especially Cyberslug for his prompt respond and examples to my problem.

CODE

#include <GUIConstants.au3>

#include <Array.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

Global $prevString

$mainwindow = GUICreate("Window Selecter",200,20,760,0)

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

WinSetOnTop($mainwindow, "", 1)

$var = WinList()

$combo = GUICtrlCreateCombo (WinGetTitle($mainwindow), 0,0); create first item

GUICtrlSetData($combo,itemList($var))

GUICtrlSetOnEvent($combo, "SwitchWindow")

GUISetState ()

; Run the GUI until the dialog is closed

While 1

$var = WinList()

$change = checkChanges($var)

If $change = 1 Then

updateCombo()

EndIf

Sleep(1000)

Wend

Func itemList(ByRef $var)

Dim $str

$str = createItemString($var)

$prevString = $str

Return $str

EndFunc

Func createItemString(ByRef $var)

Dim $str

For $i = 1 to $var[0][0]

If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then

If $var[$i][0] <> "Program Manager" Then

$str = $str & $var[$i][0] & "|"

EndIf

EndIf

Next

$str = StringTrimRight($str, 1)

Return $str

EndFunc

Func IsVisible($handle)

If BitAnd( WinGetState($handle), 2 ) Then

Return 1

Else

Return 0

EndIf

EndFunc

Func SwitchWindow()

WinActivate(GUICtrlRead($combo))

EndFunc

Func updateCombo()

$var = WinList()

GUICtrlDelete($combo)

$combo = GUICtrlCreateCombo (WinGetTitle($mainwindow), 0,0); create first item

GUICtrlSetData($combo,itemList($var))

GUICtrlSetOnEvent($combo, "SwitchWindow")

GUISetState ()

EndFunc

Func checkChanges(ByRef $var)

Dim $str

$str = createItemString($var)

If $prevString = $str Then

Return 0

Else

Return 1

EndIf

EndFunc

Func CLOSEClicked()

Exit

EndFunc

The updating process is done between the while 1....... WEnd loop. I made a few more functions to the process so that the combo box will be recreated when there is a change.

I would like to know if there is a better way to update a combo box too. Because I don't like the idea of deleting the control and recreate it again.

Edited by igmeou

[font="Arial"]Thanks[/font]
If @error = me Then $sorry
Else
   Do
      $clarifyMe
   Until $meClear
EndIF
MsgBox(0,"Special Message!","Special Thanks to " & $allHadReplied,$Forever)

Share this post


Link to post
Share on other sites
SmOke_N

Thanks Ig for

#include <GUIConstants.au3>
#include <Array.au3>
Opt ("GUIOnEventMode", 1); Change to OnEvent mode
Global $prevString
$mainwindow = GUICreate("Window Selecter", 200, 20, 760, 0)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
WinSetOnTop($mainwindow, "", 1)
$var = WinList()
$combo = GUICtrlCreateCombo(WinGetTitle($mainwindow), 0, 0); create first item
GUICtrlSetData($combo, itemList($var))
GUICtrlSetOnEvent($combo, "SwitchWindow")
GUISetState()
; Run the GUI until the dialog is closed
While 1
   $var = WinList()
   $change = checkChanges($var)
   If $change = 1 Then
      updateCombo()
   EndIf
   Sleep(1000)
WEnd
Func itemList(ByRef $var)
   Dim $str
   $str = createItemString($var)
   $prevString = $str
   Return $str
EndFunc  ;==>itemList
Func createItemString(ByRef $var)
   Dim $str
   For $i = 1 To $var[0][0]
      If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then
         If $var[$i][0] <> "Program Manager" Then
            $str = $str & $var[$i][0] & "|"
         EndIf
      EndIf
   Next
   $str = StringTrimRight($str, 1)
   Return $str
EndFunc  ;==>createItemString
Func IsVisible($handle)
   If BitAND(WinGetState($handle), 2) Then
      Return 1
   Else
      Return 0
   EndIf
EndFunc  ;==>IsVisible
Func SwitchWindow()
   WinActivate(GUICtrlRead($combo))
EndFunc  ;==>SwitchWindow
Func updateCombo()
   $var = WinList()
   GUICtrlDelete($combo)
   $combo = GUICtrlCreateCombo(WinGetTitle($mainwindow), 0, 0); create first item
   GUICtrlSetData($combo, itemList($var))
   GUICtrlSetOnEvent($combo, "SwitchWindow")
   GUISetState()
EndFunc  ;==>updateCombo
Func checkChanges(ByRef $var)
   Dim $str
   $str = createItemString($var)
   If $prevString = $str Then
      Return 0
   Else
      Return 1
   EndIf
EndFunc  ;==>checkChanges
Func CLOSEClicked()
   Exit
EndFunc  ;==>CLOSEClicked

But how do I keep my original selection in showing in the combo box window, until "I" choose to change, keeping the list refreshing at the same time?

¿RonsRules?

Edited by ronsrules

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  

×