Sign in to follow this  
Followers 0
ikaros

Remove blank items from a list view

6 posts in this topic

Hi there'

I have an application, that the user can save links to a file, while in the GUI, the file lines will be shown in a list view.

However, When i save a link to the file and adding it to the list, 2 items will be added:

a blank item - no text, just empty columns

the link item - holds the link and its name.

Is there someway to delete the blank items?

Thanks,

Share this post


Link to post
Share on other sites



#include <GUIConstants.au3>

#include <GuiListView.au3>

#include <ForumSubmitter.au3>

$fileName = "C:\AutoIt_scripts\test.txt"

$file = FileOpen($fileName, 0)

$guiWidth = 800

$guiHeight = 600

Opt("CaretCoordMode",2)

$mainWindow = GUICreate("Forum submitter",$guiWidth,$guiHeight,(@DesktopWidth-800)/2, (@DesktopHeight-700)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

GUISetState (@SW_SHOW) ; will display an empty dialog box

GUISetBkColor (0xFFFFFF)

;Save the position of the parent window

$ParentWin_Pos = WinGetPos($mainWindow, "")

;Menu

$fileMenu = GUICtrlCreateMenu("&File")

$addUrl = GUICtrlCreateMenuItem("&Add url to file",$fileMenu)

$showUrls = GUICtrlCreateMenuItem("&Show urls",$fileMenu)

$separator1 = GUICtrlCreateMenuitem ("",$filemenu,2) ; create a separator line

$exititem = GUICtrlCreateMenuitem ("Exit",$filemenu)

;Welcome label

$welcomeLbl = GUICtrlCreateLabel("Welcome to the I.D.forum submitter",200,20,350)

GUICtrlSetColor($welcomeLbl,0xff0000) ; Red

GUICtrlSetFont ($welcomeLbl,16)

;The default table

$listview = GUICtrlCreateListView(" Name | Url | Type", 80, 50, $guiWidth - 150, $guiHeight - 150, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER))

GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)

GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)

GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_TRACKSELECT, $LVS_EX_TRACKSELECT)

;Setting all columns width

_GUICtrlListViewSetColumnWidth($listview,0,100)

_GUICtrlListViewSetColumnWidth($listview,1,450)

_GUICtrlListViewSetColumnWidth($listview,2,95)

; Read in lines of text until the EOF is reached

While 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

GUICtrlCreateListViewItem($line, $listview)

Wend

FileClose($file)

#cs

These few params are the child window controls

#ce

$inserUrlBtn = ""

$forumName = ""

$forumUrl = ""

; Run the GUI until the dialog is closed

While 1

$msg = GUIGetMsg(1)

If $msg[0] = $GUI_EVENT_CLOSE Or $msg[0] = $exititem Then

If $msg[1] = $mainWindow Then

ConsoleWrite("Closing the application main window - bye bye" & @CR)

GUISwitch($mainWindow)

GUIDelete()

ExitLoop

ElseIf $msg[1] = $addUrlWindow Then

ConsoleWrite("Closing the addUrl window" & @CR)

GUISwitch($addUrlWindow)

GUIDelete()

EndIf

EndIf

;Add url window

If $msg[0] = $addUrl Then

$addUrlWindow = GUICreate("Add url",280,150,$ParentWin_Pos[0] + 200, $ParentWin_Pos[1] + 100,-1,-1,$mainWindow)

GUICtrlCreateLabel("Insert forum name : ",5,10,90,25)

$forumName = GUICtrlCreateInput("",100,5,150,25)

GUICtrlCreateLabel("Insert forum URL : ",5,50,90,25)

$forumUrl = GUICtrlCreateInput("",100,45,150,25)

$inserUrlBtn = GUICtrlCreateButton("Save & Close",80,80,120,25)

GUISetBkColor (0xFFFFFF)

GUISetState (@SW_SHOW)

While 1

$msg = GUIGetMsg()

if $msg = $inserUrlBtn Then

$responseCode = checkUrl(GUICtrlRead($forumUrl))

if(@error > 0) Then

MsgBox(0,"Error ","Please check the URL entered.")

Else

$file = FileOpen($fileName, 1)

If $file = -1 Then

ConsoleWrite("Error while openning the file")

MsgBox(16,"Error openning the file","There have been an error while trying to open " & $fileName)

Else

ConsoleWrite("Inserting data to file" & @CR)

FileWriteLine($file, @LF & GUICtrlRead($forumName) & "|" & GUICtrlRead($forumUrl) & "|")

FileClose($file)

GUICtrlCreateListViewItem("" & GUICtrlRead($forumName) & "|" & GUICtrlRead($forumUrl), $listview)

MsgBox(0,"Url saved","The url saved to the file")

ConsoleWrite("data to file inserted" & @CR)

GUIDelete()

EndIf

EndIf

EndIf

If $msg = $GUI_EVENT_CLOSE Then

ExitLoop

EndIf

WEnd

EndIf

Wend

Share this post


Link to post
Share on other sites

FileWriteLine($file, @LF & GUICtrlRead($forumName) & "|" & GUICtrlRead($forumUrl) & "|")

That @LF is the source of your problems.


"be smart, drink your wine"

Share this post


Link to post
Share on other sites

See _GUICtrlListViewDeleteItem in the help file (might be renamed in the latest beta).

But in your case solution is - don't create the problem and you won't have to fix it.

You don't need to add linefeeds when using FileWriteLine. The whole purpose of that function is that it does this for you automatically, just like its name suggests.


"be smart, drink your wine"

Share this post


Link to post
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
Sign in to follow this  
Followers 0