Jump to content



Photo

Listview in While loop


  • Please log in to reply
5 replies to this topic

#1 jazzyjeff

jazzyjeff

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 286 posts

Posted 11 May 2012 - 06:51 PM

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.

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







#2 MilesAhead

MilesAhead

    Eclectician

  • Active Members
  • PipPipPipPipPipPip
  • 531 posts

Posted 11 May 2012 - 11:27 PM

AutoIt         
#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.
"I don't want to belong to any club that would have me as a member."- Groucho Marx

#3 jazzyjeff

jazzyjeff

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 286 posts

Posted 12 May 2012 - 01:25 AM

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

#4 jazzyjeff

jazzyjeff

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 286 posts

Posted 12 May 2012 - 04:11 AM

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


#5 jazzyjeff

jazzyjeff

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 286 posts

Posted 12 May 2012 - 06:29 PM

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.

AutoIt         
[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


#6 MilesAhead

MilesAhead

    Eclectician

  • Active Members
  • PipPipPipPipPipPip
  • 531 posts

Posted 12 May 2012 - 06:29 PM

I don't understand why you are not using GuiGetMsg() instead of rolling your own.

See GuiGetMsg() in the help. It polls without running up the CPU.
Just polling one control is asking for problems.

Edited by MilesAhead, 12 May 2012 - 06:31 PM.

"I don't want to belong to any club that would have me as a member."- Groucho Marx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users