Jump to content

Stop ListBox from sorting alphabetically


Recommended Posts

Is there a way to prevent the listbox from being sorted alphabetically? I've got this rather sloppy code that is the start of something I am working on, right now it just displays the results from "net view" in a listbox and allows you to click on the PC name and it will tell you the OS the machine is running on. Problem is, "net view" doesn't return the list in alphabetical order, but listbox wants to sort it. So that means that the 300th computer in the listbox doesn't match up to the 300th computer in the array (sometimes). I noticed the $LB_SORT variable, I thought maybe that might have something to do with it, I've commented it out altogether, changed it to 0 or 1 and I've searched the forums with no luck. Here's the code that I'm embarassed to post, I took a few bits from CyberSlug:

#include <GuiConstants.au3>
#include <File.au3>
Global $LB_GETCURSEL = 0x0188;
FileDelete(@TempDir & "\templist.txt")
RunWait(@ComSpec & " /c net view > " & @TempDir & "\templist.txt", "", @SW_HIDE)
$file = @TempDir & "\templist.txt"
$lines = StringReplace(FileRead($file, FileGetSize($file)), @LF, @CR)
$lines = StringSplit($lines, @CR)
Global $compname[$lines[0]]
Global $os[$lines[0]]
Global $comp[$lines[0]]
Dim $WS_OVERLAPPEDWINDOW = 0xCF0000, $WS_VISIBLE = 0x10000000, $WS_CLIPSIBLINGS = 0x04000000

GUICreate(@LogonDomain, 200, 200, (@DesktopWidth - 380) / 2, (@DesktopHeight - 280) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
GUICtrlSetLimit(-1, 20000)
$combo = GUICtrlCreateList("", -1, -1)
$pc = 0

For $i = 1 To Int($lines[0])
   If StringLeft($lines[$i], 2) = "\\" Then
      $pc = $pc + 1
      $compname[$i] = StringLeft(StringTrimLeft($lines[$i], 2), StringInStr($lines[$i], "   ") - 3)
      $comp[$pc] = $compname[$i]
      GUICtrlSetData($combo, $compname[$i] & "|")

While 1
   $msg = GUIGetMsg()
      Case $msg = $GUI_EVENT_CLOSE
      Case Else
         If $msg = $combo Then
            $pcnumber = Int(_GuiLB_GetcurSel($combo) + 1)
            $os[$pcnumber] = RegRead("\\" & $comp[$pcnumber] & "\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion", "ProductName")
            MsgBox(0, $comp[$pcnumber], $os[$pcnumber])
FileDelete(@TempDir & "\templist.txt")

Func _GuiLB_GetCurSel($ref)
 Return GuiSendMsg($ref, $LB_GETCURSEL, 0, 0)
Link to comment
Share on other sites

See this thread http://www.autoitscript.com/forum/index.ph...wtopic=3021&hl=

#include <GuiConstants.au3>
Global $LBS_NOTIFY = 0x1, $WS_VSCROLL = 0x200000, $WS_BORDER = 0x800000;

$GUI = GuiCreate("Example")
GuiCtrlCreateList("",10, 10, 200, 200, $listboxStyle)
GuiCtrlSetData(-1, "one|two|three|four|five|six|seven|eight")

While 1
   $msg = GuiGetMsg()
   If $msg = $GUI_EVENT_CLOSE Then ExitLoop

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...