Jump to content
Sign in to follow this  
JohnBailey

A3LListView - Adding Columns to a ListView

Recommended Posts

JohnBailey

Work Around

#418324

Question

The following code demonstrates my problem, but first here it is in words: When I use _ListView_AddColumn() the Listview control does not seem to change the count of columns, so when you try to add an item to the listview that is more than the original count the item does not display.

example

#include <GUIConstants.au3>
#include <A3LListview.au3>

Opt("GUIOnEventMode", 1)
$Form2 = GUICreate("Form1", 385, 555, 233, 184)
$LV_Main = GUICtrlCreateListView("headers", 20, 26, 342, 491)
GUICtrlSendMsg(-1, 0x101E, 0, 50)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE,'GUIClose')

_LVCD_loadColumnHeaders('Name|Number',$LV_Main); Change to the desired Header List
GUICtrlCreateListViewItem('Abby|084631',$LV_Main); does not work
GUICtrlCreateListViewItem('James',$LV_Main);does work

While 1
    Sleep(100)
WEnd

Func GUIClose()
    Exit
EndFunc

Func _LVCD_loadColumnHeaders($LV_Main_headers,$lvcd_LVMain)
    Local $lvcd_LVhandle = GUICtrlGetHandle($lvcd_LVMain)
    For $lvcd_counter = 1 to _ListView_GetColumnCount($lvcd_LVhandle)
        _ListView_DeleteColumn($lvcd_LVhandle, $lvcd_counter-1)
    Next
    
    
    Local $headerSplit = StringSplit($LV_Main_headers,'|',1)
    For $lvcd_counter = 1 to $headerSplit[0]
        _ListView_AddColumn($lvcd_LVhandle, $headerSplit[$lvcd_counter])
    Next
EndFunc

Explanation (thus far)

Although the reason is unclear, GUICtrlCreateListViewItem() does not add items with subitems when the column count has previously been adjusted. As a result do not use that function. Instead, use one of the three methods as shown in the Work Around . Again, the reason is still unclear as to why the built-in function GUICtrlCreateListViewItem() does not work with adjusted columns, but as GaryFrost noted "It's usually not a good idea to mix built-in function calls with UDF calls, some you can get away with others you can't."

Edited by JohnBailey

A decision is a powerful thing

Share this post


Link to post
Share on other sites
JohnBailey

Here's the really weird thing:

ConsoleWrite('HeaderCount: '&_ListView_GetColumnCount(GUICtrlGetHandle($LV_Main)))

If that is put after the _LVCD_loadColumnHeaders() then it shows 2

Why is the item with a divider not being added?


A decision is a powerful thing

Share this post


Link to post
Share on other sites
JohnBailey

This works using _ListView_AddItem() and _ListView_AddSubItem(), but GUICtrlCreateListViewItem() does not seem to work with the A3LListView.

Does any one know if my statement is really true, or if I'm doing something weird?


A decision is a powerful thing

Share this post


Link to post
Share on other sites
SmOke_N

John, 3 posts in the same thread created by you is a bit silly, and you do it often.

Just get all your ducks in a row, and when you have a list of questions... then ask them and wait patiently.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
JohnBailey

John, 3 posts in the same thread created by you is a bit silly, and you do it often.

Just get all your ducks in a row, and when you have a list of questions... then ask them and wait patiently.

My perspective was:

  • To show I am working to resolve the issue and what I've tried. (I attempt to answer my own questions)
  • Provide help for others who have the same or similar question (I search the forum before asking my questions)
  • At the time I post my question I do have my "ducks in a row" (at least from my perspective at the moment)
  • Often questions go unanswered, so by posting what I do it shows I am trying and not just coming here to get others to do my work
  • Some times I find a work around, but my original question is not answered (for instance, this thread)
What did/do you meant/mean by "ducks in a row"? In the moment I start a thread that I do indeed have all my information setup in a logical manner. I think about my wording carefully, make the title specific (not something like "help me!", post examples if I can, and provide any external references if applicable.

If it is a no-no, to do what I do, then I will stop and only post once in my thread.

NOTE: bold was used for highlighting the important part and not for emphasis

Edited by JohnBailey

A decision is a powerful thing

Share this post


Link to post
Share on other sites
JohnBailey

Use the GuiListView UDFs in the beta, you'll get more help

GaryFrost,

Awesome!! I'll do that.

Two questions:

  • Should I abstain from what I've been doing (Am I doing a no-no)?
  • Why does GUICtrlCreateListViewItem() not work with the A3LListView functions as I demonstrated?

A decision is a powerful thing

Share this post


Link to post
Share on other sites
SmOke_N

My perspective was:

  • To show I am working to resolve the issue and what I've tried. (I attempt to answer my own questions)
  • Provide help for others who have the same or similar question (I search the forum before asking my questions)
  • At the time I post my question I do have my "ducks in a row" (at least from my perspective at the moment)
  • Often questions go unanswered, so by posting what I do it shows I am trying and not just coming here to get others to do my work
  • Some times I find a work around, but my original question is not answered (for instance, this thread)
What did/do you meant/mean by "ducks in a row"? In the moment I start a thread that I do indeed have all my information setup in a logical manner. I think about my wording carefully, make the title specific (not something like "help me!", post examples if I can, and provide any external references if applicable.

If it is a no-no, to do what I do, then I will stop and only post once in my thread.

NOTE: bold was used for highlighting the important part and not for emphasis

I didn't need a break down or an explanation. I don't care what your justification is personally, 3 posts 4 minutes apart back to back is rediculous.... Ducks in a row... (If you found all the extra stuff you are explaining above so fast, then maybe you should actually sit down, write your soon to be support post out in Notepad or Word, and see how many times you change it so that you only have 1 post until someone replies.)

I'm saying this because of how you posted ... I never even bothered to read your thread... good thing Gary is more patient than I am with it ? ... :)

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
GaryFrost

It's usually not a good idea to mix built-in function calls with UDF calls, some you can get away with others you can't.


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
JohnBailey

I didn't need a break down or an explanation. I don't care what your justification is personally, 3 posts 4 minutes apart back to back is rediculous.... Ducks in a row... (If you found all the extra stuff you are explaining above so fast, then maybe you should actually sit down, write your soon to be support post out in Notepad or Word, and see how many times you change it so that you only have 1 post until someone replies.)

I'm saying this because of how you posted ... I never even bothered to read your thread... good thing Gary is more patient than I am with it ? ... :)

eek, ok I'm starting to create havoc. I just wanted to explain what I was doing and my intentions, so everyone may know and especially you as a VERY HELPFUL bloke and as a moderator. I do not want to do something that is against the rules or suggestions of the moderators, especially when you're spending time to help.

I did not resolve my question/problem at any point during my postings. I will do as you have suggested and build a mock thread. The above posts I thought would just be interesting to note and not important in the first thread. I will do as you have suggested. I appreciate it too.

Gary was very kind indeed to read my postings!


A decision is a powerful thing

Share this post


Link to post
Share on other sites
JohnBailey

It's usually not a good idea to mix built-in function calls with UDF calls, some you can get away with others you can't.

OH!! I had no idea! I will for sure keep that in mind and make it a personal rule.

Is there a way to look at the built-in function calls - I'm so curious as to what is going on with this issue.

Edited by JohnBailey

A decision is a powerful thing

Share this post


Link to post
Share on other sites
JohnBailey

First, I must say VERY nice job on the new functions and naming scheme for the functions pertaining to <GUIListiView.au3> in the newest Beta release !!!

What I discovered is that there is no "simple" way of adding an entry like the old built-in function GUICtrlCreateListViewItem(). That single function would add a entry by use of the delimiter '|' (unless the scripter changed the default). However, the limitations of GUICtrlCreateListViewItem() renders it useless in cases where the LV columns are dynamically loaded (see below for more detail) and GUICtrlCreateListViewItem() is not compatible with any expansions to the columns from the initial LV creation. With that said, there are three methods I've found to resolve this issue (I still do not know why this problem exists). I originally did the A3LListView method, then the Production method, and then tried the Beta method per GaryFrost's suggestion. The deal is that the three methods are virtually the same methods just using different functions. It mist be nice to have a single function (eg. _GUIListView_AddEntireItem) that would do the following. Here are the three methods:

A3LListiView

; A3LListView Method

#include <GUIConstants.au3>
#include <A3LListview.au3>

Opt("GUIOnEventMode", 1)
$Form2 = GUICreate("Form1", 385, 555, 233, 184)
$LV_Main = GUICtrlCreateListView("headers", 20, 26, 342, 491)
GUICtrlSendMsg(-1, 0x101E, 0, 50)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE,'GUIClose')

Local $2DArray[2][2]
$2DArray[0][0]='John'
$2DArray[0][1]='023456'
$2DArray[1][0]='Shannon'
$2DArray[1][1]='023136'

_LVCD_loadColumnHeaders('Name|Number',$LV_Main); Change to the desired Header List
ConsoleWrite('HeaderCount: '&_ListView_GetColumnCount(GUICtrlGetHandle($LV_Main))&@LF)
_loadRowEntries($LV_Main,$2DArray)
;==========example==============
;GUICtrlCreateListViewItem('Abby|084631',$LV_Main); does not work
;GUICtrlCreateListViewItem('James',$LV_Main);does work

;_ListView_AddItem(GUICtrlGetHandle($LV_Main),'John')
;_ListView_AddSubItem(GUICtrlGetHandle($LV_Main), 1, 'Bailey', 1)
;===============================

While 1
    Sleep(100)
WEnd

Func GUIClose()
    Exit
EndFunc

Func _loadRowEntries(ByRef $lvID,$_2DArrayID,$lv_abase=0)
    If NOT IsArray($_2DArrayID) Then
        SetError('Not Array')
        Return -1
    EndIf
    For $x = $lv_abase to Ubound($_2DArrayID)-1
        Local $itemLine = ''
        For $xx = 0 to Ubound($_2DArrayID,2)-1
;   ConsoleWrite('Row: '&$x&' Column: '&$xx&' entry: '&$_2DArrayID[$x][$xx]&@LF) 
            If $xx = 0 Then
                _ListView_AddItem(GUICtrlGetHandle($lvID),$_2DArrayID[$x][$xx])
                $itemLine &= $_2DArrayID[$x][$xx]&'|'
            ElseIf $xx = UBound($_2DArrayID,2)-1 Then
                _ListView_AddSubItem(GUICtrlGetHandle($lvID), $x, $_2DArrayID[$x][$xx], $xx)
                $itemLine &= $_2DArrayID[$x][$xx]
            Else
                _ListView_AddSubItem(GUICtrlGetHandle($lvID),$x, $_2DArrayID[$x][$xx], $xx)
                $itemLine &= $_2DArrayID[$x][$xx]&'|'
            EndIf
        Next
        ConsoleWrite($itemLine&@LF)
        Local $splitA = StringSplit($itemLine,'|')
        If $splitA[0] <> Ubound($_2DArrayID,2) Then
            SetError('Loop Errored')
            Return -1
        EndIf
    Next
    Return Ubound($_2DArrayID)-1
EndFunc

Func _LVCD_loadColumnHeaders($LV_Main_headers,$lvcd_LVMain)
    Local $lvcd_LVhandle = GUICtrlGetHandle($lvcd_LVMain)
    For $lvcd_counter = 1 to _ListView_GetColumnCount($lvcd_LVhandle)
        _ListView_DeleteColumn($lvcd_LVhandle, $lvcd_counter-1)
    Next
    
    
    Local $headerSplit = StringSplit($LV_Main_headers,'|',1)
    For $lvcd_counter = 1 to $headerSplit[0]
        _ListView_AddColumn($lvcd_LVhandle, $headerSplit[$lvcd_counter])
    Next
EndFunc

Production Release

;Production (Release v3.2.8.1) Methods

#include <GUIConstants.au3>
#include <GuiListView.au3>
;#include <A3LListview.au3>

Opt("GUIOnEventMode", 1)
$Form2 = GUICreate("Form1", 385, 555, 233, 184)
$LV_Main = GUICtrlCreateListView("headers", 20, 26, 342, 491)
GUICtrlSendMsg(-1, 0x101E, 0, 50)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE,'GUIClose')

Local $2DArray[2][2]
$2DArray[0][0]='John'
$2DArray[0][1]='023456'
$2DArray[1][0]='Shannon'
$2DArray[1][1]='023136'

_LVCD_loadColumnHeaders('Name|Number',$LV_Main); Change to the desired Header List
_loadRowEntries($LV_Main,$2DArray)


While 1
    Sleep(100)
WEnd

Func GUIClose()
    Exit
EndFunc

Func _loadRowEntries(ByRef $lvID,$_2DArrayID,$lv_abase=0)
    If NOT IsArray($_2DArrayID) Then
        SetError('Not Array')
        Return -1
    EndIf
    For $x = $lv_abase to Ubound($_2DArrayID)-1
        Local $itemLine = ''
        For $xx = 0 to Ubound($_2DArrayID,2)-1
;   ConsoleWrite('Row: '&$x&' Column: '&$xx&' entry: '&$_2DArrayID[$x][$xx]&@LF) 
            If $xx = 0 Then
                Local $addPlace = _GUICtrlListViewGetItemCount ( $LV_Main )
                _GUICtrlListViewInsertItem($lvID,$addPlace,$_2DArrayID[$x][$xx])
        ;_ListView_AddItem(GUICtrlGetHandle($lvID),$_2DArrayID[$x][$xx])
                $itemLine &= $_2DArrayID[$x][$xx]&'|'
            ElseIf $xx = UBound($_2DArrayID,2)-1 Then
                _GUICtrlListViewSetItemText ($lvID, $x, $xx, $_2DArrayID[$x][$xx] )
        ;_ListView_AddSubItem(GUICtrlGetHandle($lvID), $x, $_2DArrayID[$x][$xx], $xx)
                $itemLine &= $_2DArrayID[$x][$xx]
            Else
                _GUICtrlListViewSetItemText ($lvID, $x, $xx, $_2DArrayID[$x][$xx] )
        ;_ListView_AddSubItem(GUICtrlGetHandle($lvID),$x, $_2DArrayID[$x][$xx], $xx)
                $itemLine &= $_2DArrayID[$x][$xx]&'|'
            EndIf
        Next
        ConsoleWrite($itemLine&@LF)
        Local $splitA = StringSplit($itemLine,'|')
        If $splitA[0] <> Ubound($_2DArrayID,2) Then
            SetError('Loop Errored')
            Return -1
        EndIf
    Next
    Return Ubound($_2DArrayID)-1
EndFunc

Func _LVCD_loadColumnHeaders($newLV_Main_headers,$lvcd_LVMain)
    Local $lvcd_LVhandle = GUICtrlGetHandle($lvcd_LVMain)
    Local $currentColItems = StringSplit(_GUICtrlListViewGetColumnOrder($lvcd_LVMain),"|")
    For $lvcd_counter = 0 to $currentColItems[0]
        _GUICtrlListViewDeleteColumn($lvcd_LVMain, $lvcd_counter)
      ;_ListView_DeleteColumn($lvcd_LVhandle, $lvcd_counter-1)
    Next
    
    
    Local $headerSplit = StringSplit($newLV_Main_headers,'|',1)
    For $lvcd_counter = 1 to $headerSplit[0]
        Local $currentColItems = StringSplit(_GUICtrlListViewGetColumnOrder($lvcd_LVMain),"|")
        _GUICtrlListViewInsertColumn ( $lvcd_LVMain, $currentColItems[0],$headerSplit[$lvcd_counter],0,100)
      ;_ListView_AddColumn($lvcd_LVhandle, $headerSplit[$lvcd_counter])
    Next
EndFunc

Beta Release

;Beta (Release v3.2.9.3) Methods

#include <GUIConstants.au3>
#include <GuiListView.au3>
;#include <A3LListview.au3>

Opt("GUIOnEventMode", 1)
$Form2 = GUICreate("Form1", 385, 555, 233, 184)
$LV_Main = GUICtrlCreateListView("headers", 20, 26, 342, 491)
GUICtrlSendMsg(-1, 0x101E, 0, 50)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE,'GUIClose')

Local $2DArray[2][2]
$2DArray[0][0]='John'
$2DArray[0][1]='023456'
$2DArray[1][0]='Shannon'
$2DArray[1][1]='023136'

_LVCD_loadColumnHeaders('Name|Number',$LV_Main); Change to the desired Header List
_loadRowEntries($LV_Main,$2DArray)


While 1
    Sleep(100)
WEnd

Func GUIClose()
    Exit
EndFunc

Func _loadRowEntries(ByRef $lvID,$_2DArrayID,$lv_abase=0)
    If NOT IsArray($_2DArrayID) Then
        SetError('Not Array')
        Return -1
    EndIf
    For $x = $lv_abase to Ubound($_2DArrayID)-1
        Local $itemLine = ''
        For $xx = 0 to Ubound($_2DArrayID,2)-1
;   ConsoleWrite('Row: '&$x&' Column: '&$xx&' entry: '&$_2DArrayID[$x][$xx]&@LF) 
            If $xx = 0 Then
                _GUICtrlListView_AddItem($lvID,$_2DArrayID[$x][$xx])
        ;_ListView_AddItem(GUICtrlGetHandle($lvID),$_2DArrayID[$x][$xx])
                $itemLine &= $_2DArrayID[$x][$xx]&'|'
            ElseIf $xx = UBound($_2DArrayID,2)-1 Then
                _GUICtrlListView_AddSubItem($lvID, $x, $_2DArrayID[$x][$xx], $xx)
        ;_ListView_AddSubItem(GUICtrlGetHandle($lvID), $x, $_2DArrayID[$x][$xx], $xx)
                $itemLine &= $_2DArrayID[$x][$xx]
            Else
                _GUICtrlListView_AddSubItem($lvID, $x, $_2DArrayID[$x][$xx], $xx)
        ;_ListView_AddSubItem(GUICtrlGetHandle($lvID),$x, $_2DArrayID[$x][$xx], $xx)
                $itemLine &= $_2DArrayID[$x][$xx]&'|'
            EndIf
        Next
        ConsoleWrite($itemLine&@LF)
        Local $splitA = StringSplit($itemLine,'|')
        If $splitA[0] <> Ubound($_2DArrayID,2) Then
            SetError('Loop Errored')
            Return -1
        EndIf
    Next
    Return Ubound($_2DArrayID)-1
EndFunc

Func _LVCD_loadColumnHeaders($newLV_Main_headers,$lvcd_LVMain)
    Local $lvcd_LVhandle = GUICtrlGetHandle($lvcd_LVMain)
    Local $currentColItems = _GUICtrlListView_GetColumnCount($lvcd_LVMain)
    For $lvcd_counter = 0 to $currentColItems
        _GUICtrlListView_DeleteColumn($lvcd_LVMain, $lvcd_counter)
      ;_ListView_DeleteColumn($lvcd_LVhandle, $lvcd_counter-1)
    Next
    
    
    Local $headerSplit = StringSplit($newLV_Main_headers,'|',1)
    For $lvcd_counter = 1 to $headerSplit[0]
        _GUICtrlListView_AddColumn($lvcd_LVMain, $headerSplit[$lvcd_counter],100)
      ;_ListView_AddColumn($lvcd_LVhandle, $headerSplit[$lvcd_counter])
    Next
EndFunc
Edited by JohnBailey

A decision is a powerful thing

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  

×