Sign in to follow this  
Followers 0
qwert

Need simplest way to write to ListView column

5 posts in this topic

This ListView (below) started out as a nice, one-column control that could easily be updated with _AddItem ... and cleared, entirely, when the next process cycle started.  It worked well as a running commentary of what the associated process was doing.

Everything was fine until I tried to add a file date in a second column.  I could define a second column, but I realized I didn't know how to write to that second column.  At first, I tried appending them to the _AddItem string.  Numerous other tries have only made me more confused about the basic ListView structure and update process.  For example, adding a subitem didn't work.  There are a lot of posts regarding advanced methods like how to colorize individual fields or grab content from a column.  After reading 100, I thought I would ask:

Where is help about how to write to an individual column?  This is my basic update loop:

For $i = 1 To $found[0]
    $date = "01/01/2000"
    Local $tArray = FileGetTime($found[$i])
If IsArray($tArray) Then $date = $tArray[1] & "/" & $tArray[2] & "/" & $tArray[0]
    _GUICtrlListView_AddItem($Results, $found[$i] & "|" & $date)
;   _GUICtrlListView_AddSubItem($Results, $date, 1)
Next

Thanks in advance for some help on this.

 

ListView Wrong.png

 

Share this post


Link to post
Share on other sites



For $i = 1 To $found[0]
    $date = "01/01/2000"
    Local $tArray = FileGetTime($found[$i])
If IsArray($tArray) Then $date = $tArray[1] & "/" & $tArray[2] & "/" & $tArray[0]
    _GUICtrlListView_AddSubItem($Results, _GUICtrlListView_AddItem($Results, $found[$i]), $date, 1)
Next

Should work, if I remember correctly.

You could also just use

GUICtrlCreateListViewItem(id of listview, $found[$i] & "|" & $date)

 

Share this post


Link to post
Share on other sites
Quote

Should work, if I remember correctly.

Indeed, it does.  (Your first method is the one I tried.)  But I have no idea why it does. I would have never tried to add a subitem that contains an _AddItem.

Can you recommend an "Introduction to ListView Elements"?  I couldn't find an introduction in the Wiki.  It skips to more complex issues.

Regardless, thanks very much for getting me unstuck.  I'll continue to study ListView.

 

Share this post


Link to post
Share on other sites

Lol it's pretty simple if you break down the paramters of AddSubItem and the what AddItem Returns

Quote

_GUICtrlListView_AddItem

Success: the index of the new item.
Quote

_GUICtrlListView_AddSubItem

Adds a new subitem to the control

#include <GuiListView.au3>
_GUICtrlListView_AddSubItem ( $hWnd, $iIndex, $sText, $iSubItem [, $iImage = -1] )

Parameters

$hWnd Control ID/Handle to the control
$iIndex 0-based index of the item
$sText Item or subitem text
$iSubItem 1-based index of the subitem
$iImage [optional] 0-based index of the icon in the control's image list

Putting the call to _GUIctrlListView_AddItem in the $iIndex parameter works perfectly because AddItem returns the index of the item added. Thus, we add the sub item exactly where it needs to be. And it works perfectly as is because you're only adding one sub item. Had you had more columns you'd need to store the $iIndex returned by AddSubItem in a variable and use that variable in place of where the function call is in my original example

For $i = 1 To $found[0]
    $date = "01/01/2000"
    Local $tArray = FileGetTime($found[$i])
If IsArray($tArray) Then $date = $tArray[1] & "/" & $tArray[2] & "/" & $tArray[0]
    Local $iIndex = _GUICtrlListView_AddItem($Results, $found[$i])
    _GUICtrlListView_AddSubItem($Results, $iIndex, $date, 1)
    _GUICtrlListView_AddSubItem($Results, $iIndex, "Column 3", 2)
    _GUICtrlListView_AddSubItem($Results, $iIndex, "Column 4", 3)
Next

 

Share this post


Link to post
Share on other sites

Thanks for those sections.

What was confusing is that _AddSumItem appears to be used before there's any item defined.  But in the hierarchy of statement execution, the embedded _AddItem creates the base item first.  Obviously, that's the situation.

But the code segment you added looks more "natural".  I'll stick with that sequence to avoid tripping myself up at a later time.

Thanks, again.

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