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

ListViewSelectedItemCollection

 
Post new topic   Reply to topic    KiXforms Forum Index -> Discussion
View previous topic :: View next topic  
Author Message
Floyd
KiXforms Supporter
KiXforms Supporter


Joined: 21 Apr 2004
Posts: 78

PostPosted: Thu Oct 21, 2004 10:01 am    Post subject: ListViewSelectedItemCollection Reply with quote

Hi there,

Could somebody provide an example how to use ListViewSelectedItemCollection.

My intention is to create a dual listview. The listview will contain readed values from two diffrent ini files.

Then I want to be able to mark and select items from both lists and then write the selections into e.g. batch file.

Should I use listview or is there better way?

_________________
"... Great minds talk about idea's, average minds talk about events and samll minds talks about people...!"
Back to top
View user's profile Send private message
Bonji
KiXforms Aficionado
KiXforms Aficionado


Joined: 10 Mar 2003
Posts: 393
Location: Virginia

PostPosted: Thu Oct 21, 2004 3:40 pm    Post subject: Reply with quote

Just an FYI, it would be better to post this in the starters forum versus here.

Without knowing the purpose behind the script, I don't think I can suggest anything better. Does this example of code tell you what you need as far as listviews?

Code:

Break On
$System = CreateObject("Kixtart.System")
$Form = $System.Form
$Form.Size = 400,300
$Form.Text = "Test Form"
$Form.Center
$stsBar = $Form.StatusBar
$stsBar.Text = "Select items and then clone them..."
$stsBar.Dock = "Bottom"
$grpButtons = $Form.GroupBox
$grpButtons.Size = 380,40
$grpButtons.Dock = "Bottom"
$cmdClone = $grpButtons.Button("&Clone")
$cmdClone.Size = 60,19
$cmdClone.Location = 10,10
$cmdClone.OnClick = "cmdClone_Click()"
$cmdClone.Default = 1
$cmdQuit = $grpButtons.Button("&Quit")
$cmdQuit.Size = 60,19
$cmdQuit.Location = 100,10
$cmdQuit.OnClick = "$$Form = 'Nothing'"
$cmdQuit.Cancel = 1
$lsvList1 = $Form.ListView
$lsvList1.MultiSelect = 1
$lsvList1.Dock = "Left"
$splSplitter = $Form.Splitter
$splSplitter.Dock = "Left"
$lsvList2 = $Form.ListView
$lsvList2.Dock = "Fill"

$ = $Form.Show

Populate_Lists()

While $Form.Visible
   $ = Execute($Form.DoEvents)
Loop

Function Populate_Lists()
   $ = $lsvList1.Columns.Add("Column1",60)
   $ = $lsvList1.Columns.Add("Column2",60)
   $ = $lsvList1.Columns.Add("Column3",60)
   For $Counter = 1 to 8
      $Item = $lsvList1.Items.Add("Test")
      $Item.Subitems(0).Text = "Item" + $Counter + "_1"
      $Item.Subitems(1).Text = "Item" + $Counter + "_2"
      $Item.Subitems(2).Text = "Item" + $Counter + "_3"
   Next
   $ = $lsvList2.Columns.Add("Column1",60)
   $ = $lsvList2.Columns.Add("Column2",60)
   $ = $lsvList2.Columns.Add("Column3",60)
EndFunction

Function cmdClone_Click()
   $lsvList2.Items.Clear()
   For each $Element in $lsvList1.SelectedItems
      $Item = $lsvList2.Items.Add($Element.Text)
      $Item.Subitems(0).Text = $Element.Subitems(0).Text
      $Item.Subitems(1).Text = $Element.Subitems(1).Text
      $Item.Subitems(2).Text = $Element.Subitems(2).Text
   Next
EndFunction

_________________
-Ben
Back to top
View user's profile Send private message
Floyd
KiXforms Supporter
KiXforms Supporter


Joined: 21 Apr 2004
Posts: 78

PostPosted: Fri Oct 22, 2004 7:52 am    Post subject: Reply with quote

Oh sorry, I missed the starter forum.
Here comes the scenario Im working on:

There are 2 ini files, Each of them contains a list of available software products.
The ini files contains identifyingnumber, application name, version and path to installation source directory.

e.g:
-Prodserv1.ini

[ABEB838C-A1A7-4C5D-B7E1-8B4314600137]
AppName=MSN Messanger
Version=6.2.0137
Path=\\ProdServ1\MSNM\6.2.0.137\MSNMsetup.msi
....
...and so on...

-Prodserv2.ini

[7148F0A8-6813-11D6-A77B-00B0D0142050]
AppName=Java 2 Runtime Environment
Version=1.4.2_05
Path=\\ProdServ2\JavaRT\1.4.2_05\JRTSetup.msi
....
...and so on...

First part of scenario will be to read the target ini files for avaiable product, and publish lists for both ini files in a Kixforms GUI based interface, presented in dual listview. (like your example)

e.g.


Avaiable Pruducts on ProdServ1

-MSN Messanger 6.2.0137
...and so on ...


Avaiable Pruducts on ProdServ2

-Java 2 Runtime Environment 1.4.2_05
...and so on...

Now user should be able to scroll down, mark and choose products from both lists. Once user marked all desired products, user will choose options for installation e.g. "Quiet mode /q", "No Reboot /n" etc, then click on a button which will create a installation batch file placed on e.g. users desktop.
The single batch file will contain choosen products from both lists (ini files) and choosen installation options ( /q /n etc) ,

e.g. produced patch file:

@Echo Off
Echo.
Echo Installing MSN Messanger....
\\ProdServ1\MSNM\6.2.0.137\MSNMsetup.msi /q /n
Echo.
Echo Installing Java 2 Runtime Environment....
\\ProdServ2\JavaRT\1.4.2_05\JRTSetup.msi /q /n
...
...and so on...
Del Install.bat
_______________________
Here is how I read the ini files...

$ini1 = "\\ProdServ1\ProdHome\Prodserv1.ini"
$ini2 = "\\ProdServ2\ProdHome\Prodserv2.ini"

$keys1=ReadProfileString($ini1 ,"","")
For Each $sKey1 in Split($keys1,Chr(10))
If $sKey1
$AName = ReadProfileString($ini1,$sKey1,"AppName")+@CRLF
$AVers = ReadProfileString($ini1,$sKey1,"Version")+@CRLF
$Prod1 = $AName + ' $AVers' ;
EndIf

$keys2=ReadProfileString($ini2 ,"","")
For Each $sKey2 in Split($keys2,Chr(10))
If $sKey2
$PName = ReadProfileString($ini2,$sKey2,"AppName")+@CRLF
$PVers = ReadProfileString($ini2,$sKey2,"Version")+@CRLF
$Prod2 = $PName + ' $PVers'
EndIf

Now I need help to publish readed values into a dual listview(like your example) so I can click/mark products from both list, choose installation options, and click a button to generate a installation batch file on my desktop.

Appriciate your feedback.

_________________
"... Great minds talk about idea's, average minds talk about events and samll minds talks about people...!"
Back to top
View user's profile Send private message
Bonji
KiXforms Aficionado
KiXforms Aficionado


Joined: 10 Mar 2003
Posts: 393
Location: Virginia

PostPosted: Fri Oct 22, 2004 1:19 pm    Post subject: Reply with quote

I would combine the two .ini files just to make things simpler. Just add another entry that specifies which server the program exists on.

Let me know if this script does what you are talking about...

Code:

Break On
$System = CreateObject("Kixtart.System")
$Form = $System.Form
$Form.Size = 400,300
$Form.Text = "Test Form"
$Form.Center
$stsBar = $Form.StatusBar
$stsBar.Text = "Select the apps to be installed..."
$stsBar.Dock = "Bottom"
$grpButtons = $Form.GroupBox
$grpButtons.Size = 380,40
$grpButtons.Dock = "Bottom"
$cmdSelect = $grpButtons.Button("&Select")
$cmdSelect.Size = 60,19
$cmdSelect.Location = 10,10
$cmdSelect.OnClick = "cmdSelect_Click()"
$cmdSelect.Default = 1
$cmdQuit = $grpButtons.Button("&Quit")
$cmdQuit.Size = 60,19
$cmdQuit.Location = 100,10
$cmdQuit.OnClick = "$$Form = 'Nothing'"
$cmdQuit.Cancel = 1
$lsvList1 = $Form.ListView
$lsvList1.MultiSelect = 1
$lsvList1.Dock = "Fill"

$ = $Form.Show

Populate_Lists()

While $Form.Visible
   $ = Execute($Form.DoEvents)
Loop

Function Populate_Lists()
   Dim $Counter
   $ = $lsvList1.Columns.Add("Program",220)
   $ = $lsvList1.Columns.Add("Version",80)
   $ = $lsvList1.Columns.Add("Server",70)
   $Counter = 1
   $App = ReadProfileString(@ScriptDir + "\Apps.ini","App" + $Counter,"ID")
   While $App <> ""
      $Item = $lsvList1.Items.Add("Item")
      $Item.Subitems(0).Text = ReadProfileString(@ScriptDir + "\Apps.ini","App" + $Counter,"AppName")
      $Item.Subitems(1).Text = ReadProfileString(@ScriptDir + "\Apps.ini","App" + $Counter,"Version")
      $Item.Subitems(2).Text = ReadProfileString(@ScriptDir + "\Apps.ini","App" + $Counter,"Server")
      $Item.Tag = ReadProfileString(@ScriptDir + "\Apps.ini","App" + $Counter,"Path")
      $Counter = $Counter + 1
      $App = ReadProfileString(@ScriptDir + "\Apps.ini","App" + $Counter,"ID")
   Loop
EndFunction

Function cmdSelect_Click()
   Dim $Counter
   If $lsvList1.SelectedItems.Count = 0
      $ = $Form.MessageBox("Please select one or more Applications.","Error")
      Exit 10
   EndIf
   $Option_Form = $System.Form()
   $Option_Form.Width = 225
   $Option_Form.Text = "Choose Options"
   $Counter = 1
   For Each $Element in $lsvList1.SelectedItems
      $ = Execute("$$grp$Counter = $$Option_Form.GroupBox($$Element.Subitems(0).Text)")
      $ = Execute("$$grp$Counter.Size = 200,40")
      $ = Execute("$$grp$Counter.Location = 10,($Counter - 1) * 50 + 10")
      $ = Execute("$$chkQuiet$Counter = $$grp$Counter.CheckBox('Quiet Install')")
      $ = Execute("$$chkQuiet$Counter.Size = 80,19")
      $ = Execute("$$chkQuiet$Counter.Location = 10,15")
      $ = Execute("$$chkNoReboot$Counter = $$grp$Counter.CheckBox('No Reboot')")
      $ = Execute("$$chkNoReboot$Counter.Size = 80,19")
      $ = Execute("$$chkNoReboot$Counter.Location = 100,15")
      $Counter = $Counter + 1
   Next
   $Option_Form.Height = $Counter * 50 + 40
   $cmdOption_Form_Create = $Option_Form.Button("&Create")
   $cmdOption_Form_Create.Size = 60,19
   $cmdOption_Form_Create.Location = 40,$Counter * 50 - 25
   $cmdOption_Form_Create.OnClick = "cmdOption_Form_Create_Click()"
   $cmdOption_Form_Create.Default = 1
   $cmdOption_Form_Cancel = $Option_Form.Button("&Cancel")
   $cmdOption_Form_Cancel.Size = 60,19
   $cmdOption_Form_Cancel.Location = 120,$Counter * 50 - 25
   $cmdOption_Form_Cancel.OnClick = "$$Option_Form = 'Nothing'"
   $cmdOption_Form_Cancel.Cancel = 1
   $ = $Option_Form.Show()
EndFunction

Function cmdOption_Form_Create_Click()
   Dim $Counter, $Options
   $Counter = 1
   $ = Open(1,@ScriptDir + "\Install.bat",5)
   $ = Writeline(1,"@@Echo Off" + @CRLF)
   For Each $Element in $lsvList1.SelectedItems
      $ = Writeline(1,"Echo." + @CRLF)
      $ = Writeline(1,"Echo Installing " + $Element.Subitems(0).Text + @CRLF)
      $ = Execute("If $$chkQuiet$Counter.Value = 1   $$Options = ' /q'   EndIf")
      $ = Execute("If $$chkNoReboot$Counter.Value = 1   $$Options = $$Options + ' /n'   EndIf")
      $ = Writeline(1,$Element.Tag + $Options + @CRLF)
      $Options = ""
      $Counter = $Counter + 1
   Next
   $ = Close(1)
   $Option_Form = "Nothing"
EndFunction


And here's the supporting .ini file that defines the applications.

Code:

[App1]
ID=ABEB838C-A1A7-4C5D-B7E1-8B4314600137
AppName=MSN Messanger
Version=6.2.0137
Path=\\ProdServ1\MSNM\6.2.0.137\MSNMsetup.msi
Server=ProdServ1

[App2]
ID=7148F0A8-6813-11D6-A77B-00B0D0142050
AppName=Java 2 Runtime Environment
Version=1.4.2_05
Path=\\ProdServ2\JavaRT\1.4.2_05\JRTSetup.msi
Server=ProdServ2

[App3]
ID=1
AppName=Test App 1
Version=1.0.1
Path=\\Test\setup.exe
Server=ProdServ1

[App4]
ID=2
AppName=Test App 2
Version=1.0.1
Path=\\Test\setup.exe
Server=ProdServ1

[App5]
ID=3
AppName=Test App 3
Version=1.0.1
Path=\\Test\setup.exe
Server=ProdServ2

[App6]
ID=4
AppName=Test App 4
Version=1.0.1
Path=\\Test\setup.exe
Server=ProdServ2

_________________
-Ben
Back to top
View user's profile Send private message
Floyd
KiXforms Supporter
KiXforms Supporter


Joined: 21 Apr 2004
Posts: 78

PostPosted: Sat Oct 23, 2004 3:23 pm    Post subject: Reply with quote

Unfortunately its not allowed to combine or change the two .ini files. (readonly).
I have to keep these ini files separately, allthough the single generated batch file will contain choosen products from both ini files.
This means that user must be able to choose product from both lists.
I have created two listviews, the left one will list the products & versions from ini file1, while the right listview lists products & versions from ini file2.
I dont know if there is a property or way which enables multi item selection from both lists as same time. It should be possible...
I have increased the size for grpButtons area where i have collected and put options like:
Installtion mode: "Silent" - "No reboot" - "Remove Batch file after installtion completed"
"Install selected products on local machine"
"Create Installer.bat on target machines desktop"
"Choose name for Installer file and put it on:"
These options could be created using CheckBox and RadioButtons.
Having options on same interface, we could have a "Create/Run" button instead of "select"...

Here is what I have done:

Break On
$System = CreateObject("Kixtart.System")
$Form = $System.Form
$Form.Size = 800,600
$Form.Text = "Test"
$Form.Center
$stsBar = $Form.StatusBar
$stsBar.Text = "Select the apps to be installed..."
$stsBar.Dock = "Bottom"
$grpButtons = $Form.GroupBox
$grpButtons.Size = 380,100
$grpButtons.Dock = "Bottom"

$CheckBox1 = $grpButtons.Controls.CheckBox
$CheckBox1.Anchor = 5
$CheckBox1.Checked = "false"
$CheckBox1.Enabled = "True"
$CheckBox1.Height = 21
$CheckBox1.FontUnderline = "False"
$CheckBox1.Left = 440
$CheckBox1.Text = "Silent mode"
$CheckBox1.Top = 50
$CheckBox1.Visible = "True"
$CheckBox1.Width = 90

$CheckBox3 = $grpButtons.Controls.CheckBox
$CheckBox3.Anchor = 5
$CheckBox3.Checked = "false"
$CheckBox3.Enabled = "True"
$CheckBox3.Height = 21
$CheckBox3.FontUnderline = "False"
$CheckBox3.Left = 440
$CheckBox3.Text = "No reboot"
$CheckBox3.Top = 30
$CheckBox3.Visible = "True"
$CheckBox3.Width = 70

$CheckBox2 = $grpButtons.Controls.CheckBox
$CheckBox2.Anchor = 5
$CheckBox2.Checked = "false"
$CheckBox2.Enabled = "True"
$CheckBox2.Height = 21
$CheckBox2.Left = 440
$CheckBox2.Text = "Remove Installer file after installtion completed"
$CheckBox2.Top = 10
$CheckBox2.Visible = "True"
$CheckBox2.Width = 285

$UserInp = $grpButtons.Controls.TextBox
$UserInp.Anchor = 5
$UserInp.AcceptsReturn = "False"
$UserInp.AcceptsTab = "False"
$UserInp.BorderStyle = 2
$UserInp.Enabled = "True"
$UserInp.FontName = "Tahoma"
$UserInp.FontSize = 8
$UserInp.Height = 20
$UserInp.Left = 200
$UserInp.Text = ""
$UserInp.Top = 10
$UserInp.Visible = "True"
$UserInp.Width = 155
$UserInp.WordWrap = "False"

$RadioButton1 = $grpButtons.Controls.RadioButton
$RadioButton1.Anchor = 5
$RadioButton1.Checked = "false"
$RadioButton1.Enabled = "True"
$RadioButton1.FlatStyle = 2
$RadioButton1.Height = 21
$RadioButton1.Left = 15
$RadioButton1.Text = "Name and put Installer file here:"
$RadioButton1.Top = 10
$RadioButton1.Visible = "True"
$RadioButton1.Width = 175


$RadioButton2 = $grpButtons.Controls.RadioButton
$RadioButton2.Anchor = 5
$RadioButton2.Checked = "false"
$RadioButton2.Enabled = "True"
$RadioButton2.FlatStyle = 2
$RadioButton2.Height = 21
$RadioButton2.Left = 15
$RadioButton2.Text = "Create Installer.bat on target machines desktop"
$RadioButton2.Top = 33
$RadioButton2.Visible = "True"
$RadioButton2.Width = 255

$RadioButton3 = $grpButtons.Controls.RadioButton
$RadioButton3.Anchor = 5
$RadioButton3.Checked = "false"
$RadioButton3.Enabled = "True"
$RadioButton3.FlatStyle = 2
$RadioButton3.Height = 21
$RadioButton3.Left = 15
$RadioButton3.Text = "Install selected products on local machine"
$RadioButton3.Top = 55
$RadioButton3.Visible = "True"
$RadioButton3.Width = 225

$CrButton = $grpButtons.Controls.ToolButton
$CrButton.Anchor = 5
$CrButton.TextAlign = 32
$CrButton.Enabled = "True"
$CrButton.FlatStyle = 2
$CrButton.FontBold = "False"
$CrButton.FontItalic = "False"
$CrButton.FontName = "Tahoma"
$CrButton.FontSize = 8
$CrButton.Height = 25
$CrButton.icon = ""
$CrButton.Left = 650
$CrButton.Style = 1
$CrButton.Text = "Create/Run"
$CrButton.Top = 60
$CrButton.Visible = "True"
$CrButton.Width = 101
$CrButton.OnClick = "CreateClick()"


$lsvList1 = $Form.ListView
$lsvList1.Height = 225
$lsvList1.Left = 12
$lsvList1.Top = 15
$lsvList1.Width = 385
$lsvList1.MultiSelect = 1
$lsvList1.Dock = "Left"
$splSplitter = $Form.Splitter
$splSplitter.Dock = "centre"
$lsvList2 = $Form.ListView
$lsvList2.Height = 425
$lsvList2.Left = 375
$lsvList2.Top = 15
$lsvList2.Width = 400
$lsvList2.MultiSelect = 1
$lsvList2.Dock = "right"

$ = $Form.Show


Populate_Lists()

While $Form.Visible
$ = Execute($Form.DoEvents)
Loop

Function Populate_Lists()

$Gapp = "\\ProdServ1\inifile1.ini"
$Oapp = "\\ProdServ2\inifile2.ini"

Dim $Counter
$ = $lsvList1.Columns.Add("Program",220)
$ = $lsvList1.Columns.Add("Version",80)
$ = $lsvList2.Columns.Add("Program",220)
$ = $lsvList2.Columns.Add("Version",80)


$keys = ReadProfileString($Gapp,"","")

For Each $sKey in Split($keys,Chr(10))
If $sKey
$Item = $lsvList1.Items.Add("Item")
$Item.Subitems(0).Text = ReadProfileString($Gapp,$sKey,"AppName")+@CRLF
$Item.Subitems(1).Text = ReadProfileString($Gapp,$sKey,"Version")+@CRLF
EndIf
Next

$okeys = ReadProfileString($Oapp,"","")

For Each $oKey in Split($okeys,Chr(10))
If $oKey
$Item = $lsvList2.Items.Add("Item")
$Item.Subitems(0).Text = ReadProfileString($Oapp,$oKey,"AppName")+@CRLF
$Item.Subitems(1).Text = ReadProfileString($Oapp,$oKey,"Version")+@CRLF
EndIf
Next

EndFunction

Function CreateClick()
______________________

I dont know how to procced from here.....
Appriciate your feedback....

_________________
"... Great minds talk about idea's, average minds talk about events and samll minds talks about people...!"
Back to top
View user's profile Send private message
Floyd
KiXforms Supporter
KiXforms Supporter


Joined: 21 Apr 2004
Posts: 78

PostPosted: Sun Oct 24, 2004 5:41 pm    Post subject: Reply with quote

Found these options for ListView:

HideSelection = "False" (To be able to see/capture items selected from both listviews as same time)
MultiSelect = 1
CheckBoxes = "True"

Trying to figure out how to use these options to be able to select items from both listviews as same time, and this without holding down Ctrl button, while selecting items.

Found also KeyDown and CtrlDown options. Mayby we could use these to make Crtl key stay down while user selects items from listviews, whitout actually holding down the Ctrl button.

_________________
"... Great minds talk about idea's, average minds talk about events and samll minds talks about people...!"
Back to top
View user's profile Send private message
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Mon Oct 25, 2004 11:55 am    Post subject: Reply with quote

Floyd wrote:

Found also KeyDown and CtrlDown options. Mayby we could use these to make Crtl key stay down while user selects items from listviews, whitout actually holding down the Ctrl button.


Dunno where you found CtrlDown (not in KF I think) but KeyDown must be OnKeyDown which is supposed to trigger a keyboard event but won't be able to generate a Keypress ... This is [currently] not possible at all in KF.

Dunno what tools are out there to generate keyboard activity, but I am sure there are some

_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
maciep
KiXforms Regular
KiXforms Regular


Joined: 01 May 2003
Posts: 43
Location: Pittsburgh,PA

PostPosted: Mon Oct 25, 2004 3:26 pm    Post subject: Reply with quote

Why not have a third listview that you can add/remove the apps that the user wants to install. And in the 'tag' property of each item in that listview, store any information (path,ini file,section etc) that you need for that particular install.

When the user is finished choosing their installs, then you can just concentrate all of your efforts on that third listview.
Back to top
View user's profile Send private message
maciep
KiXforms Regular
KiXforms Regular


Joined: 01 May 2003
Posts: 43
Location: Pittsburgh,PA

PostPosted: Mon Oct 25, 2004 5:59 pm    Post subject: Reply with quote

Actually, it would probably be easier to just use checkboxes in each of the listviews. And then just loop through each of them and install any items that are checked.
Back to top
View user's profile Send private message
Floyd
KiXforms Supporter
KiXforms Supporter


Joined: 21 Apr 2004
Posts: 78

PostPosted: Mon Oct 25, 2004 6:59 pm    Post subject: Reply with quote

Oh, sorry. my bad. the CtrlDown And KeyDown property are standars in .net.
I like the idea with third listview where user can add/remove products.
Lets see if i could make it work....

_________________
"... Great minds talk about idea's, average minds talk about events and samll minds talks about people...!"
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Discussion 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