Jump to content

Recommended Posts

Posted

Hi AutoIT GUI masters!

I was wondering if you could help me out on a little challenge that I have...

I want to use a ListView that has a possible listing(items) between 0 to 30. But I wanted the form and the control to auto-adjust it's height according to the number of items in the ListView control.

Posted

Maybe this UDF, by Melba23, can help - GUIListViewEx. I don't know if this UDF has the ability to do any 'autosizing', so it's up to you to read up on it! Good luck!

That is a very good ListView UDF however it doesn't have what I was looking for...Hmmmmm... :)

Posted

Look at GuiCtrlSetPos in the help file, you can use it by adjusting the Height parameter to however many items are in your listview, while keeping the other parameters the same as when you created it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

You can think many ways to do that, this is one of them.

#include <GuiListView.au3>
Opt("GUIResizeMode",545) ; $GUI_DOCKTOP + $GUI_DOCKHEIGHT
global $n = 0
global $items[1]
$hGui = GuiCreate("AutoSize my monoscout999",-1,199)
$iButton1 = GuiCtrlCreateButton("Add Item", 260,20,120,50)
$iButton2 = GuiCtrlCreateButton("Delete Item", 260,100,120,50)
$iList = GuiCtrlCreateListView("Nª|Listview test|blabla",0,0,250,200)
$hList = GuiCtrlGetHandle($iList)
GuiSetState()
While True
    $msg = GuiGetMsg()
    Switch $msg
        case -3
            Exit
        case $iButton1
            $n += 1
            redim $items[$n]
            $items[$n-1] = GUICtrlCreateListViewItem($n&"|Some text|more text", $iList)
            $Height = _GUICtrlListView_ApproximateViewHeight($hList)
            $pos = wingetpos($hGui)
            If $pos[3]-27 < $Height Then
                winmove($hGui,"", $pos[0],$pos[1],$pos[2],$Height+30)
                GUICtrlSetPos($iList,0,0,250,$Height+30)
            EndIf
        case $iButton2
            If $n > 0 then
            GuiCtrldelete($items[$n-1])
            $n -= 1
            $Height = _GUICtrlListView_ApproximateViewHeight($hList)
            $pos = wingetpos($hGui)
            If $pos[3]-27 > $Height and $pos[3]-27 > 200 Then
                winmove($hGui,"", $pos[0],$pos[1],$pos[2],$Height+30)
                GUICtrlSetPos($iList,0,0,250,$Height+30)
            EndIf
            EndIf
    EndSwitch
WEnd
Posted

You can think many ways to do that, this is one of them.

#include <GuiListView.au3>
Opt("GUIResizeMode",545) ; $GUI_DOCKTOP + $GUI_DOCKHEIGHT
global $n = 0
global $items[1]
$hGui = GuiCreate("AutoSize my monoscout999",-1,199)
$iButton1 = GuiCtrlCreateButton("Add Item", 260,20,120,50)
$iButton2 = GuiCtrlCreateButton("Delete Item", 260,100,120,50)
$iList = GuiCtrlCreateListView("Nª|Listview test|blabla",0,0,250,200)
$hList = GuiCtrlGetHandle($iList)
GuiSetState()
While True
    $msg = GuiGetMsg()
    Switch $msg
        case -3
            Exit
        case $iButton1
            $n += 1
            redim $items[$n]
            $items[$n-1] = GUICtrlCreateListViewItem($n&"|Some text|more text", $iList)
            $Height = _GUICtrlListView_ApproximateViewHeight($hList)
            $pos = wingetpos($hGui)
            If $pos[3]-27 < $Height Then
                winmove($hGui,"", $pos[0],$pos[1],$pos[2],$Height+30)
                GUICtrlSetPos($iList,0,0,250,$Height+30)
            EndIf
        case $iButton2
            If $n > 0 then
            GuiCtrldelete($items[$n-1])
            $n -= 1
            $Height = _GUICtrlListView_ApproximateViewHeight($hList)
            $pos = wingetpos($hGui)
            If $pos[3]-27 > $Height and $pos[3]-27 > 200 Then
                winmove($hGui,"", $pos[0],$pos[1],$pos[2],$Height+30)
                GUICtrlSetPos($iList,0,0,250,$Height+30)
            EndIf
            EndIf
    EndSwitch
WEnd

As always monoscout999, nice and brilliant code! This is exactly what i need. Thank you!

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