Jump to content

Listview in While loop


Recommended Posts

I have 2 lists:

- 1 a Listbox

- The other a Listview

When I click on the Listbox item, I want the Listview to populate the first column with data stored in an ini file. The problem is the Listview never gets populated with items from the ini file.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>
Global $listBuilding, $listRoom
Global $lb, $lr, $lrText, $p
$Form1 = GUICreate("Form1", 396, 371, 192, 124)
$listBuilding = GUICtrlCreateList("", 16, 40, 169, 292)
GUICtrlSetData(-1, "Test|Alpha|Beta")
$listRoom = _GUICtrlListView_Create($Form1, "", 204, 42, 169, 292)
$btnConnect = GUICtrlCreateButton("Connect", 296, 336, 75, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$lb = GUICtrlRead($listBuilding)
If $lb = "Admin" Then
  $lr = IniReadSection("[url="file://\\app2\apps$\K-12\Projectors\projectors.ini"]C:\projectors.ini[/url]", "Test")
  For $p = 1 To $lr[0][0]
   $lrText = _GUICtrlListView_GetItemText($listRoom, $p - 1)
   MsgBox(0, "", "Loop: " & $p & @CR & "Listview item text: " & $lrText & @CR & "ini list for Projector: " & $lr[$p][0])
   If $lr[$p][0] = $lrText Then
    MsgBox(0, "", "Match")
    Sleep(1);MsgBox(0, "", _GUICtrlListView_GetItemText($listRoom, $p) & @CR & @error)
   Else
    MsgBox(0, "", "No Match")
    _GUICtrlListView_AddItem($listRoom, $lr[$p][0])
   EndIf
  Next
Wend

Because I have this in a while loop I have it so that if the item matches whats already in the listview, it just sleeps briefly. If they don't match, then the listview item is added.

I appreciate any help.

Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>
Global $listBuilding, $listRoom
Global $lb, $lr, $lrText, $p
$Form1 = GUICreate("Form1", 396, 371, 192, 124)
$listBuilding = GUICtrlCreateList("", 16, 40, 169, 292)
GUICtrlSetData(-1, "Test|Admin|Alpha|Beta")
$listRoom = _GUICtrlListView_Create($Form1, "", 204, 42, 169, 292)
$btnConnect = GUICtrlCreateButton("Connect", 296, 336, 75, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
    $lb = GUICtrlRead($listBuilding)
    If $lb = "Admin" Then
        $lr = IniReadSection("[url="file://app2apps$K-12Projectorsprojectors.ini"]C:projectors.ini[/url]", "Test")
        For $p = 1 To $lr[0][0]
            $lrText = _GUICtrlListView_GetItemText($listRoom, $p - 1)
            MsgBox(0, "", "Loop: " & $p & @CR & "Listview item text: " & $lrText & @CR & "ini list for Projector: " & $lr[$p][0])
            If $lr[$p][0] = $lrText Then
                MsgBox(0, "", "Match")
                Sleep(1);MsgBox(0, "", _GUICtrlListView_GetItemText($listRoom, $p) & @CR & @error)
            Else
                MsgBox(0, "", "No Match")
                _GUICtrlListView_AddItem($listRoom, $lr[$p][0])
            EndIf
        Next
    EndIf
WEnd

I cleaned it up a bit. But since I don't have the .ini file I can't read a section. You test for "Admin" but there's no Admin value in the list. So I added it. Also looks like the ini read section has some problems with the quoting.

Link to comment
Share on other sites

Thanks for your response MilesAhead.

I just made a typo with the "Admin" part, but that wasn't/isn't the issue with the script. Also, the path in the IniReadSection just went weird when I pasted it into the forum.

The ini file looks like this:

[Admin]

Row 1=10.10.10.10

Row 2=10.10.10.11

Row 3=10.10.10.12

Link to comment
Share on other sites

I am still trying to figure this out, so if anyone has any ideas I'd appreciate it. My latest attempt, and I think it is closer, is to have 2 ListBox's in instead of a Listbox and a ListView.

The 2nd list refreshes correctly and doesn't flicker with the constant looping. The problem now though is that I can't select and item in that 2nd list because it keeps trying to read the last item in the list.

here is the code.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
Global $listBuilding, $listRoom
Global $lb, $lr, $lrText, $p
$Form1 = GUICreate("Form1", 396, 371, 192, 124)
$listBuilding = GUICtrlCreateList("", 16, 40, 169, 292)
GUICtrlSetData(-1, [color="#008080"]"Test|Admin|Alpha|Beta"[/color])
$listRoom = GUICtrlCreateList("", 204, 42, 169, 292)
$btnConnect = GUICtrlCreateButton("Connect", 296, 336, 75, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$lb = GUICtrlRead($listBuilding)
;MsgBox(0, "", $lb)
If $lb = "Admin" Then
$lr = IniReadSection("C:\projectors.ini","Admin")
$total = $lr[0][0]
$lrText = GUICtrlRead($listRoom)
;MsgBox(0, "", $lrText & @CR & $lr[$total][0])
If $lr[$total][0] <> $lrText Then
For $p = 1 To $lr[0][0]
;MsgBox(0, "", "Loop: " & $p & @CR & "Listview item text: " & $lrText & @CR & "ini list for Projector: " & $lr[$p][0])
GUICtrlSetData($listRoom, $lr[$p][0])
Next
EndIf
EndIf
Wend
Link to comment
Share on other sites

Ok, I figured this out. The code is below if anyone else needs to do something similar. Maybe there is a better way, but it works for me.

[font=monospace]
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
Global $listBuilding, $listRoom
Global$lb, $lr, $lrText, $p
Global $chk = ""
$Form1 = GUICreate("Form1, 396, 371, 192, 124)
$listBuilding = GUICtrlCreateList("", 16, 40, 169, 292)
GUICtrlSetData(-1, Test|Admin|Alpha|Beta")
$listRoom = GUICtrlCreateList("",204, 42, 169, 292)
$btnConnect = GUICtrlCreateButton("Connect", 296, 336, 75, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$lb = GUICtrlRead($listBuilding)
;MsgBox(0, "", $lb)
If $lb = "Admin" Then
  If $lb <> $chk Then
   $lr = IniReadSection("C:\Projectors.ini", "Admin")
   $total = $lr[0][0]
   $lrText = GUICtrlRead($listRoom)
   ;MsgBox(0, "", $lrText & @CR & $lr[$total][0])
   If $lr[$total][0] <> $lrText Then
    For $p = 1 To $lr[0][0]
     ;MsgBox(0, "", "Loop: " & $p & @CR & "Listview item text: " & $lrText & @CR & "ini list for Projector: " & $lr[$p][0])
     GUICtrlSetData($listRoom, $lr[$p][0])
    Next
    $chk = "Admin"
   EndIf
  EndIf
Wend
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...