KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

ListView in Powershell what am I doing wrong?

 
Post new topic   Reply to topic    KiXforms Forum Index -> Starters Code Clinic
View previous topic :: View next topic  
Author Message
Scrib
KiXforms Novice
KiXforms Novice


Joined: 09 Jun 2010
Posts: 2

PostPosted: Mon Jul 08, 2013 10:28 am    Post subject: ListView in Powershell what am I doing wrong? Reply with quote

I'm trying to use Listview, via Admin Script Editor, using powershell. I can get Listview to populate the first column with data, but I can't get it to work with more than one column. If I do I get errors like this:

Method invocation failed because [System.Management.Automation.PSMethod] doesn't contain a method named 'SubItems'.

Can anyone help?

Heres my code, to display a simple test Listview:

#region Script Settings
#<ScriptSettings xmlns="http://tempuri.org/ScriptSettings.xsd">
# <ScriptPackager>
# <process>powershell.exe</process>
# <arguments />
# <extractdir>%TEMP%</extractdir>
# <files />
# <usedefaulticon>true</usedefaulticon>
# <showinsystray>false</showinsystray>
# <altcreds>false</altcreds>
# <efs>true</efs>
# <ntfs>true</ntfs>
# <local>false</local>
# <abortonfail>true</abortonfail>
# <product />
# <version>1.0.0.1</version>
# <versionstring />
# <comments />
# <includeinterpreter>false</includeinterpreter>
# <forcecomregistration>false</forcecomregistration>
# <consolemode>false</consolemode>
# <EnableChangelog>false</EnableChangelog>
# <AutoBackup>false</AutoBackup>
# <snapinforce>false</snapinforce>
# <snapinshowprogress>false</snapinshowprogress>
# <snapinautoadd>0</snapinautoadd>
# <snapinpermanentpath />
# </ScriptPackager>
#</ScriptSettings>
#endregion

#region ScriptForm Designer

#region Constructor

$System = New-Object -ComObject "Kixforms.System"

#endregion

#region Post-Constructor Custom Code

#endregion

#region Form Creation
#Warning: It is recommended that changes inside this region be handled using the ScriptForm Designer.
#When working with the ScriptForm designer this region and any changes within may be overwritten.

#~~< Form1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$Form1 = $System.Form()
$Form1.Text = "Form1"
#~~< ListView1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$ListView1 = $Form1.Controls.Add($System.ListView())
$ListView1.Size = $System.Size(204, 207)
$ListView1.View = 1
#~~< ListView1.Columns >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$Name = $ListView1.Columns.Add($System.ColumnHeader())
$Name.Text = "Name"
$Address = $ListView1.Columns.Add($System.ColumnHeader())
$Address.Text = "Address"
$Phone = $ListView1.Columns.Add($System.ColumnHeader())
$Phone.Text = "Phone"
$ListView1.Text = "ListView1"
$ListView1.TabIndex = 0
$ListView1.Location = $System.Point(68, 30)

#endregion

#region Custom Code

#endregion

#region Event Loop

function Main{
$System.Application().EnableVisualStyles()
$Form1.Show()
while($Form1.Visible){
$command=$System.DoEvents()
if($command){Invoke-Expression $command}
}
}

#endregion

#endregion

#region Event Handlers

for ($i=1;$i -le 10;$i++)
{

Write-Host ">>" $i
$Item = $ListView1.Items.Add
$Item.SubItems(0).Text = "John Doe"
$Item.SubItems(1).Text = "74 Maple Drive"
$Item.SubItems(2).Text = "905-555-1234"
}


Main # This call must remain below all other event functions

#endregion
Back to top
View user's profile Send private message
Viggen
KiXforms Regular
KiXforms Regular


Joined: 28 Jun 2005
Posts: 40

PostPosted: Tue Aug 27, 2013 9:09 am    Post subject: Reply with quote

It's been a while since I used kix, but I think that if you change this:
Code:
$Item = $ListView1.Items.Add
$Item.SubItems(0).Text = "John Doe"
$Item.SubItems(1).Text = "74 Maple Drive"
$Item.SubItems(2).Text = "905-555-1234"


to:
Code:
$Item = $ListView1.Items.Add
$Item.SubItems.Item(0).Text = "John Doe"
$Item.SubItems.Item(1).Text = "74 Maple Drive"
$Item.SubItems.Item(2).Text = "905-555-1234"


it should work
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Starters Code Clinic All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group