Jump to content

Blank Listview Item


Recommended Posts

This is the code:

_GUICtrlListViewDeleteColumn($nListview, 1)
    $varBuddies = INIRead("C:\buddies.ini", "BuddyList", "Buddies", "Unable to read INI.")
    $array = StringSplit($varBuddies, ";"); Splits the string up by using semi-colons as delimiters
    _ArrayDelete ( $array, 0 )
    _GUICtrlListViewInsertColumn($nListview, 1, "Buddy Name", 0, 110)
    For $val In $array
        If $val <> "" Then $items = GUICtrlCreateListViewItem("|" & $val, $nListview); Creates the listview items from the INI file
    Next

It firsts deletes the column in the center, then reads items from my ini. Splits, the items by semicolons. Now I re-insert the column I deleted and then do a For Next Loop that basically creates all of the values in my .ini into listview items.

But in the process of doing this, it generates one blank line per times it goes through the For Loop.

What did I do wrong in this code?

Just a guess but maybe my problem has to do with when I re-inserted the column?

Edited by FireLordZi
While Alive() {
	 DrinkWine();
}
AutoIt Programmer
Link to comment
Share on other sites

FireLordZi

Hi! Try this example:

#include <GuiListView.au3>
#include <GuiConstantsEx.au3>

$Gui = GUICreate("Test", 300, 200)

$hListView = _GUICtrlListView_Create($GUI, "Items|SubItems1|SubItems2", 20, 15, 260, 150, BitOR($LVS_EDITLABELS, $LVS_REPORT), $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_SUBITEMIMAGES)

_GUICtrlListView_AddItem($hListView, "Item1")
_GUICtrlListView_AddItem($hListView, "Item2")
_GUICtrlListView_AddItem($hListView, "Item3")
_GUICtrlListView_AddItem($hListView, "Item4")

_GUICtrlListView_AddSubItem ($hListView, 0,'44', 1)
_GUICtrlListView_AddSubItem ($hListView, 1,'22', 1)
_GUICtrlListView_AddSubItem ($hListView, 2,'11', 1)
_GUICtrlListView_AddSubItem ($hListView, 3,'33', 1)

_GUICtrlListView_AddSubItem ($hListView, 0,'New', 2)
_GUICtrlListView_AddSubItem ($hListView, 1,'Page', 2)
_GUICtrlListView_AddSubItem ($hListView, 2,'Sys', 2)
_GUICtrlListView_AddSubItem ($hListView, 3,'Device', 2)

$button = GUICtrlCreateButton("Delete", 20, 170, 50, 25)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
        ExitLoop
    Case $button
        SetNewItems()
    EndSwitch
WEnd

Func SetNewItems()
    Local $varBuddies, $array
    
    $varBuddies = INIRead("C:\buddies.ini", "BuddyList", "Buddies", "None")
    
    If $varBuddies = "None" Then
        MsgBox(16, "Error", "Unable to read INI")
        Return 0
    EndIf
    
    $array = StringSplit($varBuddies, ";"); Splits the string up by using semi-colons as delimiters
    
    For $i = 1 To $array[0]
        ConsoleWrite($array[$i] & @CRLF)
        _GUICtrlListView_SetItem($hListView, $array[$i], $i - 1, 1)
    Next
EndFunc

:)

Link to comment
Share on other sites

FireLordZi

Hi! Try this example:

#include <GuiListView.au3>
#include <GuiConstantsEx.au3>

$Gui = GUICreate("Test", 300, 200)

$hListView = _GUICtrlListView_Create($GUI, "Items|SubItems1|SubItems2", 20, 15, 260, 150, BitOR($LVS_EDITLABELS, $LVS_REPORT), $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_SUBITEMIMAGES)

_GUICtrlListView_AddItem($hListView, "Item1")
_GUICtrlListView_AddItem($hListView, "Item2")
_GUICtrlListView_AddItem($hListView, "Item3")
_GUICtrlListView_AddItem($hListView, "Item4")

_GUICtrlListView_AddSubItem ($hListView, 0,'44', 1)
_GUICtrlListView_AddSubItem ($hListView, 1,'22', 1)
_GUICtrlListView_AddSubItem ($hListView, 2,'11', 1)
_GUICtrlListView_AddSubItem ($hListView, 3,'33', 1)

_GUICtrlListView_AddSubItem ($hListView, 0,'New', 2)
_GUICtrlListView_AddSubItem ($hListView, 1,'Page', 2)
_GUICtrlListView_AddSubItem ($hListView, 2,'Sys', 2)
_GUICtrlListView_AddSubItem ($hListView, 3,'Device', 2)

$button = GUICtrlCreateButton("Delete", 20, 170, 50, 25)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
        ExitLoop
    Case $button
        SetNewItems()
    EndSwitch
WEnd

Func SetNewItems()
    Local $varBuddies, $array
    
    $varBuddies = INIRead("C:\buddies.ini", "BuddyList", "Buddies", "None")
    
    If $varBuddies = "None" Then
        MsgBox(16, "Error", "Unable to read INI")
        Return 0
    EndIf
    
    $array = StringSplit($varBuddies, ";"); Splits the string up by using semi-colons as delimiters
    
    For $i = 1 To $array[0]
        ConsoleWrite($array[$i] & @CRLF)
        _GUICtrlListView_SetItem($hListView, $array[$i], $i - 1, 1)
    Next
EndFunc

:)

Too bad I don't have the lastest version... :)

And thanks anyway but that has absolutely nothing to do with what I'm talking about.

Edited by FireLordZi
While Alive() {
	 DrinkWine();
}
AutoIt Programmer
Link to comment
Share on other sites

Just download latest beta.

An to the script - you are wrong there is everything in it to delete a listview item.

you just need to parse the items and search for empty ones

1. I can't download the latests until I finish my script because it's too big.

2. I don't have any problems deleting listview items, its finding them.

Everytime I add a value to my ini though my program it reads it back into the program as a listview item

but also creates a blank space. So maybe it would be easier to point out the problem with my code instead of

creating a script that will take a while to try to get it incorporated with my own.

While Alive() {
	 DrinkWine();
}
AutoIt Programmer
Link to comment
Share on other sites

So maybe it would be easier to point out the problem with my code instead of

creating a script that will take a while to try to get it incorporated with my own.

Try loading the data into an array before putting it into the ListView.

It's easy to search through an array for empty elements, not so easy to search through a ListView unless you have indexed each ListViewItem.

I've done pretty much the same thing in a previous program.

Data --> ARRAY

Delete empty elements in array

ARRAY --> LISTVIEW

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

The code you postet has no error.

Can´t reproduce

CODE
;Using an Array

#include <GUIConstants.au3>

Dim $aArray[4]

$aArray[0]="a"

$aArray[1]=""

$aArray[2]=1.3434

$aArray[3]="test"

GUICreate("listview items",220,250, 100,200,-1,$WS_EX_ACCEPTFILES)

GUISetBkColor (0x00E0FFFF) ; will change background color

GuiCtrlSetState(-1,$GUI_DROPACCEPTED) ; to allow drag and dropping

$listview = GuiCtrlCreateListView ("col1 |col2|col3 ",10,10,200,150);,$LVS_SORTDESCENDING)

GuiSetState()

$string = ""

FOR $element IN $aArray

If $element <> "" Then $items = GUICtrlCreateListViewItem("|" & $element, $listview);

NEXT

GuiSetState()

Msgbox(0,"For..IN Arraytest","Result is: " & @CRLF & $string)

;Using an Object Collection

$oShell = ObjCreate("shell.application")

$oShellWindows=$oShell.windows

if Isobj($oShellWindows) then

$string=""

for $Window in $oShellWindows

$String = $String & $window.LocationName & @CRLF

next

msgbox(0,"","You have the following windows open:" & @CRLF & $String)

else

msgbox(0,"","you have no open shell windows.")

endif

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