Jump to content

problem with gui lists


tamir
 Share

Recommended Posts

hi,

i have two lists in a gui window and i want to edit their text.

i have a script that make all the gui stuff and here's the relevant part where i edit the lists:

;------------------list number 1----------------------;
$list_a = GUICtrlCreateList("", 20, 40, 100)
$files_num_a = _FileNum($dir_a)
_FilesAddToList($list_a, $dir_a,"",  $files_num_a)
;------------------list number 1----------------------;



;------------------list number 2----------------------;
$list_b = GUICtrlCreateList("", 250, 40, 100)
$files_num_b = _FileNum($dir_b)
_FilesAddToList($list_b, $dir_b,"",  $files_num_b)
;------------------list number 2----------------------;

the function _FileNum gets the number of files in the given folder.

$dir_a and $dir_b r both @ScriptDir

the function _FilesAddToList suppose to add the files names to the given list:

Func _FilesAddToList($listHandle, $targetDir, $type,  $filesNumber)
   If $type == "" Then $type = "*.*"

   GuiCtrlSetData($listHandle, "")

   $scan = FileFindFirstFile($targetDir & "\" & $type)

   For $i = 1 to $filesNumber
   $scan = FileFindNextFile($scan)


   If NOT ($scan == "." OR $scan == "..") Then
      GuiCtrlSetData($listHandle, $scan & "|")
   EndIf
   Next

EndFunc

i think that's all the information u need.

the problem is that it's only edit the first list.

if i disable the first list's editing the other list editing working good.

so what's the problem?

Link to comment
Share on other sites

Try:

Func _FilesAddToList($listHandle, $targetDir, $type)
   If $type == "" Then $type = "*.*"
   
   $scan = FileFindFirstFile($targetDir & "\" & $type)
   
   $list = ''
   While $scan <> - 1
      $file = FileFindNextFile($scan)
      If @error Then
         FileClose($scan)
         ExitLoop
      EndIf
      
      If NOT ($file == "." Or $file == "..") Then
         $list = $list & '|' & $file
      EndIf
   WEnd
   
   GUICtrlSetData($listHandle,)
EndFunc  ;==>_FilesAddToList

And...

Don't mess with handles. The variant that keep handles must stay untouched until FileClose(9

You dont need $filenumber, how did you had this idea?

It is better updating controls only once.

Updating a list with a string that starts with pipe destroy the old list. As you see the loop I made make a string that starts with a pipe for this reason, no need for GUICtrlSetData($listHandle, "")

Edited by ezzetabi
Link to comment
Share on other sites

it works, thanks.

i didn't understand that part:

While $scan <> - 1

what is it for?

can i just write "While 1" ?

<{POST_SNAPBACK}>

While $scan <> - 1 makes the loop exit, when FileFindNextFile errors to find another file.

While 1, does not do this.

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...