Jump to content

If I Add A Column,


randallc
 Share

Recommended Posts

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
Link to comment
Share on other sites

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


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

Link to comment
Share on other sites

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