Jump to content
Sign in to follow this  
randallc

If I Add A Column,

Recommended Posts

randallc

Hi,

If I add a column, can I still add an item to a listview?

I try adding these commands to the help example, but the first line does nothing, and the second (surprisingly?) changes the header line!??

GUICtrlCreateListViewItem("line6|data6|more6|extra6", $listview)

GUICtrlSetData($listview,"line6|data6|more6|extra6" )

#include <GuiConstants.au3>

#include <GuiListView.au3>

opt('MustDeclareVars', 1)

Dim $listview, $Btn_InsertCol, $Btn_Exit, $msg, $Input_col, $Status

GUICreate("ListView Insert Column", 392, 322)

$listview = GUICtrlCreateListView("col1|col2|col3", 40, 30, 310, 149)

GUICtrlCreateListViewItem("line1|data1|more1", $listview)

GUICtrlCreateListViewItem("line2|data2|more2", $listview)

GUICtrlCreateListViewItem("line3|data3|more3", $listview)

GUICtrlCreateListViewItem("line4|data4|more4", $listview)

GUICtrlCreateListViewItem("line5|data5|more5", $listview)

GUICtrlCreateLabel("Enter Column # to Insert:", 90, 190, 130, 20)

$Input_col = GUICtrlCreateInput("", 220, 190, 80, 20, $ES_NUMBER)

GUICtrlSetLimit($Input_col, 1)

$Btn_InsertCol = GUICtrlCreateButton("Insert Column", 150, 230, 90, 40)

$Btn_Exit = GUICtrlCreateButton("Exit", 300, 260, 70, 30)

$Status = GUICtrlCreateLabel("Remember columns are zero-indexed", 0, 302, 392, 20, BitOR($SS_SUNKEN, $SS_CENTER))

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit

ExitLoop

Case $msg = $Btn_InsertCol

If (StringLen(GUICtrlRead($Input_col)) > 0) Then

If (_GUICtrlListViewInsertColumn ($listview, Int(GUICtrlRead($Input_col)), "test", 0, 40)) Then

GUICtrlCreateListViewItem("line6|data6|more6|extra6", $listview)

GUICtrlSetData($listview,"line6|data6|more6|extra6" )

GUICtrlSetData($Status, 'Insert column: ' & GUICtrlRead($Input_col) & ' Successful')

Else

GUICtrlSetData($Status, 'Failed to Insert column: ' & GUICtrlRead($Input_col))

EndIf

Else

GUICtrlSetData($Status, 'Must enter a column to insert')

EndIf

EndSelect

WEnd

Exit

Best, Randall

Share this post


Link to post
Share on other sites
BigDod

Try this

#include <GuiConstants.au3>
#include <GuiListView.au3>

opt('MustDeclareVars', 1)
Dim $listview, $Btn_InsertCol, $Btn_Exit, $msg, $Input_col, $Status
GUICreate("ListView Insert Column", 392, 322)

$listview = GUICtrlCreateListView("col1|col2|col3", 40, 30, 310, 149)
GUICtrlCreateListViewItem("line1|data1|more1", $listview)
GUICtrlCreateListViewItem("line2|data2|more2", $listview)
GUICtrlCreateListViewItem("line3|data3|more3", $listview)
GUICtrlCreateListViewItem("line4|data4|more4", $listview)
GUICtrlCreateListViewItem("line5|data5|more5", $listview)
GUICtrlCreateLabel("Enter Column # to Insert:", 90, 190, 130, 20)
$Input_col = GUICtrlCreateInput("", 220, 190, 80, 20, $ES_NUMBER)
GUICtrlSetLimit($Input_col, 1)
$Btn_InsertCol = GUICtrlCreateButton("Insert Column", 150, 230, 90, 40)
$Btn_Exit = GUICtrlCreateButton("Exit", 300, 260, 70, 30)
$Status = GUICtrlCreateLabel("Remember columns are zero-indexed", 0, 302, 392, 20, BitOR($SS_SUNKEN, $SS_CENTER))

GUISetState()
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
         ExitLoop
      Case $msg = $Btn_InsertCol
         If (StringLen(GUICtrlRead($Input_col)) > 0) Then
            If (_GUICtrlListViewInsertColumn ($listview, Int(GUICtrlRead($Input_col)), "col" & Int(GUICtrlRead($Input_col)), 0, 40)) Then
               GUICtrlSetData($Status, 'Insert column: ' & GUICtrlRead($Input_col) & ' Successful')
               _GUICtrlListViewInsertItem ($listview,-1,"line6|data6|more6|extra6")
            Else
               GUICtrlSetData($Status, 'Failed to Insert column: ' & GUICtrlRead($Input_col))
            EndIf
         Else
            GUICtrlSetData($Status, 'Must enter a column to insert')
        EndIf


   EndSelect
WEnd
Exit


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites
GaryFrost

Hi,

second (surprisingly?) changes the header line!??

Best, Randall

you did speicify the listview control not a listview item, so suprise.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
randallc

Hi,

_GUICtrlListViewInsertItem ($listview,-1,"line6|data6|more6|extra6")

1. thanks ; that helps a lot . I have a number of GUIs hacked together, but never written from scratch, and there are so many commands!

[PS Does this mean we no longer need the CreateListViewItem command, or does this replace it as a better command?]

you did speicify the listview control not a listview item, so suprise.

2. I was referring to the surprise of finding an easier way to re-set Column Headers; you originally worked up the new SetColumnHeader function when I didn't know how to do this, but it was already built-in to this command1

best, Randall

Edited by randallc

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  

×