View previous topic :: View next topic |
Author |
Message |
CluM09 KiXforms Follower

Joined: 29 May 2007 Posts: 25
|
Posted: Tue Feb 24, 2009 11:05 pm Post subject: Parse multiple selected items from a ListBox |
|
|
Hello,
I have populated the listbox with some items in the array.
Now how can I parse the selected items back from the listbox?
Thanks. |
|
Back to top |
|
 |
benny69 KiXforms Advocate


Joined: 30 Oct 2003 Posts: 567 Location: Lincoln, Ne
|
Posted: Wed Feb 25, 2009 12:26 pm Post subject: |
|
|
Hi CluM09,
Here is a ListBox Multi-Select Example, maybe it will get you started:
Code: |
Break On
$System = CreateObject("Kixforms.System")
If Not $System
$nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
Quit()
EndIf
$Form1 = $System.Form()
$Form1.StartPosition = 1 ;FormStartPosition_CenterScreen
$Form1.Size = $System.Size(338,224) ;(Width,Height)
$Form1.Text = "ListBox Example"
$ListBox1 = $System.ListBox()
$ListBox1.DoubleClick = "AddToListBox2()"
$ListBox1.Height = 173
$ListBox1.Left = 10
$ListBox1.SelectionMode = 3 ;MultiExtended
$ListBox1.Top = 10
$nul = $Form1.Controls.Add($ListBox1)
For $Index = 1 to 6
$Item = $ListBox1.Items.Add("Line"+$Index)
Next
$Button1 = $System.Button()
$Button1.Click = "AddAllToListBox2()"
$Button1.Height = 30
$Button1.Left = 150
$Button1.Text = ">>"
$Button1.Top = 30
$Button1.Width = 30
$nul = $Form1.Controls.Add($Button1)
$Button2 = $System.Button()
$Button2.Click = "AddToListBox2()"
$Button2.Height = 30
$Button2.Left = 150
$Button2.Text = ">"
$Button2.Top = 70
$Button2.Width = 30
$nul = $Form1.Controls.Add($Button2)
$Button3 = $System.Button()
$Button3.Click = "RemoveFromListBox2()"
$Button3.Height = 30
$Button3.Left = 150
$Button3.Text = "<"
$Button3.Top = 110
$Button3.Width = 30
$nul = $Form1.Controls.Add($Button3)
$Button4 = $System.Button()
$Button4.Click = "RemoveAllFromListBox2()"
$Button4.Height = 30
$Button4.Left = 150
$Button4.Text = "<<"
$Button4.Top = 150
$Button4.Width = 30
$nul = $Form1.Controls.Add($Button4)
$ListBox2 = $System.ListBox()
$ListBox2.DoubleClick = "RemoveFromListBox2()"
$ListBox2.Height = 173
$ListBox2.Left = 200
$ListBox2.SelectionMode = 3 ;MultiExtended
$ListBox2.Top = 10
$nul = $Form1.Controls.Add($ListBox2)
$Form1.Show ;Displays the Form
While $Form1.Visible
$Nul = Execute($Form1.DoEvents())
Loop
Exit 0
Function AddAllToListBox2()
$ListBox2.Items.Clear
For $x = 0 to $ListBox1.Items.Count
If $ListBox1.Items.Item($x) <> ""
$Item = $ListBox2.Items.Add($ListBox1.Items.Item($x))
EndIf
Next
EndFunction
Function AddToListBox2()
For $Index = 0 to $ListBox1.SelectedItems.Count
$ListItem = "No"
For $x = 0 to $ListBox2.Items.Count
If $ListBox2.Items.Item($x) = $ListBox1.SelectedItems.Item($Index)
$ListItem = "Yes"
EndIf
Next
If $ListItem = "No"
$Item = $ListBox2.Items.Add($ListBox1.SelectedItems.Item($Index))
EndIf
Next
For $Index = 0 to $ListBox1.Items.Count
$ListBox1.SetSelected($Index,0)
Next
EndFunction
Function RemoveFromListBox2()
For $Index = 0 to $ListBox2.SelectedItems.Count
$ListBox2.Items.Remove($ListBox2.SelectedItem)
Next
EndFunction
Function RemoveAllFromListBox2()
$ListBox2.Items.Clear
EndFunction
|
_________________ Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta) |
|
Back to top |
|
 |
CluM09 KiXforms Follower

Joined: 29 May 2007 Posts: 25
|
Posted: Wed Feb 25, 2009 2:30 pm Post subject: |
|
|
benny69,
Thank you for the hep.
I just figured out that I can just iterate the SeletedItems property of the ListBox, and I am able to parse the multi-selected items from the ListBox.
It appears that ListBox.SelectedItems is a array instead.
I am doing this with VBScript.
Code: |
Function getListBoxItems()
Dim objItem
For Each objItem in ListBox1.SelectedItems
MsgBox objItem
Next
End Function
|
I would tend to think that I can also do this with Kixtart if Kixtart is the language that I use. |
|
Back to top |
|
 |
Lonkero KiXforms Devotee


Joined: 13 Mar 2003 Posts: 1022 Location: Espoo, Finland
|
Posted: Wed Feb 25, 2009 8:17 pm Post subject: |
|
|
yes, that's exactly what you would do with kixtart. kinda.
kixtart com support is a bit different from vbscript, so not everything works quite the same.
although, if that for each doesn't work, one would need to ask shawn why, cause basically he holds the answer to that. _________________ Hammer |
|
Back to top |
|
 |
CluM09 KiXforms Follower

Joined: 29 May 2007 Posts: 25
|
Posted: Wed Jan 20, 2010 11:59 pm Post subject: |
|
|
Hello,
Is there any way I can deselect the items in the listbox?
Thanks. |
|
Back to top |
|
 |
CluM09 KiXforms Follower

Joined: 29 May 2007 Posts: 25
|
Posted: Sun Jan 24, 2010 6:05 pm Post subject: |
|
|
I just fingured it out how to deselect the items in the listbox. It was the code from another post. The code is listed below:
For $Index = 0 to $ListBox1.Items.Count
$ListBox1.SetSelected($Index,0)
Next
This code will deselect all the items in the listbox including those items that were not selected. However, it does the job for what I need. |
|
Back to top |
|
 |
|