Jump to content

Need help understanding GUICtrlCreateListViewItem


ttleser
 Share

Recommended Posts

I want to create a simple program that will scan multiple computers in a certain directory for any files with certain key words in it. I want to use have a Listview that'll show all 20 computers across the top of the table and all the files it finds listed below the appropriate computer.

For example, I've got 20 computers I need to scan for files. In the Gui it'll have a box that I'll fill in the directory path of where I want it to scan (but we'll use c:\test for now) and of course a button that'll say "scan". I want to click on scan and have the program scan computer1 for the files and list them underneath computer1 in the table, then do onto computer2 and so forth.

I'm pretty sure I can get the Do loop setup properly to scan each computer, but I'm unsure how to setup the listview properly.

Link to comment
Share on other sites

OK, here's my script so far. Still need a little help though.

GUICreate("File Search", 850, 400)

GUISetState()
$listView = GUICtrlCreateListView("PC1|PC2|PC3|PC4|PC5|PC6|PC7|PC8|PC9|PC10|PC11|PC12|PC13|PC14|PC15|PC16|PC17|PC18|PC19|PC20", 0, 80, 850, 150)
$button_scan = GUICtrlCreateButton('&Scan', 5, 290, 75, 23)
$button_exit = GUICtrlCreateButton('E&xit', 90, 290, 75, 23)
GUICtrlCreateLabel ("File Name",  10, 10)
$name = GUICtrlCreateInput ("", 70, 10, 300, 20)
GUICtrlCreateLabel ("Directory",  10, 40)
$dir = GUICtrlCreateInput ("", 70, 40, 300, 20)

While 1

    $msg = GUIGetMsg()
    Select
        Case $msg = $button_exit
            Exit
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $button_scan
        $directory  = GUICtrlRead($dir)
        $filename = GUICtrlRead($name)
            $IP = 1
            $sep = ""
            _GUICtrlListViewDeleteAllItems($listView)
            Do
                DriveMapAdd("y:", "\\192.168.100."&$IP&"\c$")
                FileChangeDir("y:\"&$directory)
                $search = FileFindFirstFile($filename&".*")
                While 1
                    $file = FileFindNextFile($search) 
                    If @error Then ExitLoop
                    GUICtrlCreateListViewItem($sep&$file, $listView)
                WEnd
                $sep = "|"&$sep
                $IP = $IP + 1
            Until $IP = 4

    EndSelect

WEnd

The script works good, it'll scan each computer (just got it set to scan 3 computers for now) and it'll display the results in the table the way I want it with one small problem. It does scan computer 1 and display the info in the 1st column correctly, when it scans the 2nd computer it'll display the information on the next column but it starts it after the 1st column got done, same with the 3rd computer..

So, for example. Say there are 2 files on each computer that match the criteria I set. That's 6 total files that'll display. Here's how it displays after I click "scan" (please ignore the dashes as I needed to use them in these forums to show the proper formatting for you guys.)

PC1-------PC2-------PC3

file1

file2

------------file1

------------file2

-----------------------file1

-----------------------file2

Link to comment
Share on other sites

I think for you will be better use this ListView structure:

Computer File name

----------- -----------

PC1 file1

PC1 file2

PC2 file1

PC2 file2

PC3 file1

PC3 file3

Because on each computer can be different count of files.

Or maybe use treeview instead of listview.

In first level will be nodes for computers each with child nodes of files.

Link to comment
Share on other sites

Sorry, that won't work for me. There'll probably be like 20+ files per computer at 20 computers equals alot of files. Anyone else know on how I can make the table appear correctly??

Make array of file names for each computer.

Then in FOR loop compose strings for every listview line from all that arrays.

You must check different bounds of each arrarys and add "" when neccessary.

Link to comment
Share on other sites

Ok, how about this. I could just have 20 listviews, 1 for each of the computers. I would have them side by side, like:

$listView1 = GUICtrlCreateListView("PC1", 0, 80, 20, 150)

$listView2 = GUICtrlCreateListView("PC2", 20, 80, 20, 150)

$listView3 = GUICtrlCreateListView("PC3", 40, 80, 20, 150)

$listView4 = GUICtrlCreateListView("PC4", 60, 80, 20, 150)

$listView5 = GUICtrlCreateListView("PC5", 80, 80, 20, 150)

etc

But, for my loop, how do I make it so that the line: GUICtrlCreateListViewItem($sep&$file, $listView1) has the variable $listview incremented by 1 each time the "do loop" happens again.

Also, how can I get _GUICtrlListViewGetItemText() to report which itemview and line that was selected. Say I choose file#2 on listview#4, is there a way to report which listview was selected as well as what was selected?

Thoughts?

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