JazzM
(Getting the hang of it)
2004-10-31 05:33 PM
ListView.OnDoubleClick

Need an example how to Add items from a listview to another, by double clicking.

Assume that ListView1 is populated with several items, and listview2 is empty. By double clicking on an items presented in listview1, the item should be placed in/moved to listview2, And vice versa.

Anybody with good ideas?



Sealeopard
(KiX Master)
2004-10-31 05:55 PM
Re: ListView.OnDoubleClick

See the ListViewColumns oject in the KiXforms Manual. It contains an example on how to add columns to a listview. Use the ListViewSelectedItemCollection to grab the currently selected column.

JazzM
(Getting the hang of it)
2004-10-31 06:16 PM
Re: ListView.OnDoubleClick

Where do u find this ListViewSelectedItemCollection ...
Its not much regading ListViewSelectedItemCollection at Kixforms BBS or Doc...

hmmmm...not much for help....


ShawnAdministrator
(KiX Supporter)
2004-10-31 06:30 PM
Re: ListView.OnDoubleClick

Here's a quickie example:

Code:

Break on

$System = CreateObject("Kixtart.System")

$Form = $System.Form()
$Form.Size = 640,480
$Form.Text = "Bigglesworth-Ware"

$ToolBar = $Form.GroupBox()
$ToolBar.Height = 30
$ToolBar.Dock = "Top"
$ToolBar.DockPadding = 2

$ListView1 = $Form.ListView()
$ListView1.Dock = "Left"
$ListView1.Right = $Form.ClientWidth / 2
$ListView1.SmallImageList = $System.BuiltinImageList
$ListView1.HideSelection = 0
$ListView1.OnDoubleClick = "ListView1DoubleClick()"

$Col = $ListView1.Columns.Add("Installed Software",-2)

For $i = 0 to 10
$Item = $ListView1.Items.Add("Package#$i",$i)
Next

For Each $Item In $ListView1.SelectedItems
$Item.Selected = 0
Next

$ListView1.Columns(0).Width = -1
$ListView1.Columns(0).Width = -2
$ListView1.Sorted = 1

$Splitter = $Form.Splitter()

$ListView2 = $Form.ListView()
$ListView2.Dock = "Fill"
$ListView2.SmallImageList = $System.BuiltinImageList
$ListView2.HideSelection = 0
$ListView2.OnDoubleClick = "ListView2DoubleClick()"

$= $ListView2.Columns.Add("Available Software",-2)

For $i = $i to 20
$Item = $ListView2.Items.Add("Package#$i",$i)
Next

For Each $Item In $ListView2.SelectedItems
$Item.Selected = 0
Next

$ListView2.Columns(0).Width = -1
$ListView2.Columns(0).Width = -2
$ListView2.Sorted = 1

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

Exit 1

Function ListView1DoubleClick()

dim $item

$item = $ListView2.Items.Add($ListView1.FocusedItem.Text,$ListView1.FocusedItem.ImageIndex)
$ListView1.FocusedItem.Remove()

EndFunction

Function ListView2DoubleClick()

dim $item

$item = $ListView1.Items.Add($ListView2.FocusedItem.Text,$ListView2.FocusedItem.ImageIndex)
$ListView2.FocusedItem.Remove()

EndFunction




JazzM
(Getting the hang of it)
2004-10-31 08:36 PM
Re: ListView.OnDoubleClick

Great Shawn :-)

U R D Best!

happy halloween



JazzM
(Getting the hang of it)
2004-11-01 11:33 AM
Re: ListView.OnDoubleClick

Shawn, If the listviews has several Sub-items, how should i define the function to get everything moved on doubleclick?

e.g.
$ListView1.Items.Add
$Item.Subitems(0).Text
$Item.Subitems(1).Text
$Item.Subitems(2).Text
$Item.Subitems(3).Text


ShawnAdministrator
(KiX Supporter)
2004-11-01 02:12 PM
Re: ListView.OnDoubleClick

Your right, should be able to use SubItems(n) to move all the stuff back and forth, for example:

Code:

Break on

$System = CreateObject("Kixtart.System")

$Form = $System.Form()
$Form.Size = 640,480
$Form.Text = "Bigglesworth-Ware"

$ToolBar = $Form.GroupBox()
$ToolBar.Height = 30
$ToolBar.Dock = "Top"
$ToolBar.DockPadding = 2

$ListView1 = $Form.ListView()
$ListView1.Dock = "Left"
$ListView1.Right = $Form.ClientWidth / 2
$ListView1.OnDoubleClick = "ListView1DoubleClick()"

$= $ListView1.Columns.Add("A")
$= $ListView1.Columns.Add("B")
$= $ListView1.Columns.Add("C")

For $i = 0 to 30 Step 3
$Item = $ListView1.Items.Add($i)
$Item.SubItems(1).Text = $i+1
$Item.SubItems(2).Text = $i+2
Next

$Splitter = $Form.Splitter()

$ListView2 = $Form.ListView()
$ListView2.Dock = "Fill"
$ListView2.OnDoubleClick = "ListView2DoubleClick()"

$= $ListView2.Columns.Add("A")
$= $ListView2.Columns.Add("B")
$= $ListView2.Columns.Add("C")

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

Exit 1

Function ListView1DoubleClick()

dim $item

$item = $ListView2.Items.Add($ListView1.FocusedItem.Text,$ListView1.FocusedItem.ImageIndex)

$item.SubItems(1).Text = $ListView1.FocusedItem.SubItems(1).Text
$item.SubItems(2).Text = $ListView1.FocusedItem.SubItems(2).Text

$ListView1.FocusedItem.Remove()

EndFunction

Function ListView2DoubleClick()

dim $item

$item = $ListView1.Items.Add($ListView2.FocusedItem.Text,$ListView2.FocusedItem.ImageIndex)

$item.SubItems(1).Text = $ListView2.FocusedItem.SubItems(1).Text
$item.SubItems(2).Text = $ListView2.FocusedItem.SubItems(2).Text

$ListView2.FocusedItem.Remove()

EndFunction




JazzM
(Getting the hang of it)
2004-11-20 03:35 PM
Re: ListView.OnDoubleClick

Thanx Shawn,

Just a quick Q:

How do I add an "specific" smallimage/icon on items in listview?

e.g. Icon=34
or
Image=C:\Icons\Myicon.ico




Sealeopard
(KiX Master)
2004-11-20 04:39 PM
Re: ListView.OnDoubleClick

By adding images to the ImageList collection via the ImageCollection.Add method.

ShawnAdministrator
(KiX Supporter)
2004-11-20 05:49 PM
Re: ListView.OnDoubleClick

Jens is spot on ...

1) Plug the builtin (kixforms) imagelist into both ListViews like this:

Code:


$ListView1.SmallImageList = $System.BuiltinImageList

$ListView2.SmallImageList = $System.BuiltinImageList



if you need custom icons in the list, then you have to "Add" them.

2) Specify the ImageIndex of the each item, like this (we're just using a random image index for this example):

Code:


$Item.ImageIndex = rnd(50)



And thats all there is ... please note - you can only specify an icon for the first item in a row ... subitems can't have icons. Heres the full example:

Code:


Break on

$System = CreateObject("Kixtart.System")

$Form = $System.Form()
$Form.Size = 640,480
$Form.Text = "Bigglesworth-Ware"

$ToolBar = $Form.GroupBox()
$ToolBar.Height = 30
$ToolBar.Dock = "Top"
$ToolBar.DockPadding = 2

$ListView1 = $Form.ListView()
$ListView1.Dock = "Left"
$ListView1.Right = $Form.ClientWidth / 2
$ListView1.OnDoubleClick = "ListView1DoubleClick()"
$ListView1.SmallImageList = $System.BuiltinImageList

$= $ListView1.Columns.Add("A")
$= $ListView1.Columns.Add("B")
$= $ListView1.Columns.Add("C")

For $i = 0 to 30 Step 3
$Item = $ListView1.Items.Add($i)
$Item.ImageIndex = rnd(50)
$Item.SubItems(1).Text = $i+1
$Item.SubItems(2).Text = $i+2
Next

$Splitter = $Form.Splitter()

$ListView2 = $Form.ListView()
$ListView2.Dock = "Fill"
$ListView2.OnDoubleClick = "ListView2DoubleClick()"
$ListView2.SmallImageList = $System.BuiltinImageList

$= $ListView2.Columns.Add("A")
$= $ListView2.Columns.Add("B")
$= $ListView2.Columns.Add("C")

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

Exit 1

Function ListView1DoubleClick()

dim $item

$item = $ListView2.Items.Add($ListView1.FocusedItem.Text,$ListView1.FocusedItem.ImageIndex)

$item.SubItems(1).Text = $ListView1.FocusedItem.SubItems(1).Text
$item.SubItems(2).Text = $ListView1.FocusedItem.SubItems(2).Text

$ListView1.FocusedItem.Remove()

EndFunction

Function ListView2DoubleClick()

dim $item

$item = $ListView1.Items.Add($ListView2.FocusedItem.Text,$ListView2.FocusedItem.ImageIndex)

$item.SubItems(1).Text = $ListView2.FocusedItem.SubItems(1).Text
$item.SubItems(2).Text = $ListView2.FocusedItem.SubItems(2).Text

$ListView2.FocusedItem.Remove()

EndFunction



-Shawn


JochenAdministrator
(KiX Supporter)
2004-11-20 07:44 PM
Re: ListView.OnDoubleClick

Quote:

Where do u find this ListViewSelectedItemCollection ...
Its not much regading ListViewSelectedItemCollection at Kixforms BBS or Doc...

hmmmm...not much for help....




Jazz, is it possible that you overlooked the kixforms.chm help file yet ?
If yes, find information about ListViewSelectedItemCollection included in the latest development build helpfile


JazzM
(Getting the hang of it)
2004-11-21 05:09 PM
Re: ListView.OnDoubleClick

I cannot get it work on my code:

$lsvList1 = $Form.ListView

$lsvList1.Height = 425
$lsvList1.Left = 12
$lsvList1.Top = 15
$lsvList1.Width = 200
$lsvList1.MultiSelect = 0
$lsvList1.Dock = "Left"
$lsvList1.OnDoubleClick = "lsvList1DC()"

$lsvListQ = $Form.ListView
$lsvListQ.Height = 110
$lsvListQ.Left = 590
$lsvListQ.Top = 15
$lsvListQ.Width = 270
$lsvListQ.MultiSelect = 1


$ = $lsvList1.Columns.Add("Name",180)
$ = $lsvList1.Columns.Add("Version",80)
$ = $lsvList1.Columns.Add("Path",0)
$ = $lsvList1.Columns.Add("ID",0)

$SWProd = "\\Server1\Share\Software1\Prroduct1.ini"

$Item0 = $lsvList1.Items.Add("")

$key = ReadProfileString($SWProd,"","")

For Each $Keys In Split($key,Chr(10))
If $Keys
$Item = $lsvList1.Items.Add()
$Item.Text = "Item"
$Name = ReadProfileString($SWProd,$Keys,"SWName")+@CRLF
$Item.Subitems(0).Text = $Name
$Ver = ReadProfileString($SWProd $Keys,"SWVersion")+@CRLF
$Item.Subitems(1).Text = $Ver
$Path = ReadProfileString($SWProd,$Keys,"SWPath")+@CRLF
$Item.Subitems(2).Text = $Path
$Item.Subitems(3).Text = $Keys
$NmVr = $Name + $Ver


$lsvList1.Columns.Sorted = "True"
$lsvList1.item.Sorted = "True"

$lsvList1.HideSelection = "true"
EndIf

Function lsvList1DC()

Dim $item

$item = $lsvListQ.Items.Add($lsvList1.FocusedItem.Text,$lsvList1.FocusedItem.ImageIndex)

;here i want a specifict icon for each item which addes to this listview!
;e.g. Icon=34 or Image=C:\Icons\Myicon.ico, not any random ico or image

$item.SubItems(1).Text = $lsvList1.FocusedItem.SubItems(1).Text
$item.SubItems(2).Text = $lsvList1.FocusedItem.SubItems(2).Text
$item.SubItems(3).Text = $lsvList1.FocusedItem.SubItems(3).Text

EndIf
EndFunction



Les
(KiX Master)
2004-11-21 05:34 PM
Re: ListView.OnDoubleClick

Why do you have an ENDIF in your lsvList1DC() function?

JazzM
(Getting the hang of it)
2004-11-21 09:16 PM
Re: ListView.OnDoubleClick

Ahh... why the endif is there½!"# just ignore it...

Sealeopard
(KiX Master)
2004-11-22 01:44 AM
Re: ListView.OnDoubleClick

That's not how it works over here. An ENDIF without corresponding IF will screw up your code.

JazzM
(Getting the hang of it)
2004-11-22 02:25 PM
Re: ListView.OnDoubleClick

Now its gone. damn endif is gone/removed. ignore=delete

Function lsvList1DC()

Dim $item

$item = $lsvListQ.Items.Add($lsvList1.FocusedItem.Text,$lsvList1.FocusedItem.ImageIndex)

;here i want a specifict icon for each item which addes to this listview!
;e.g. Icon=34 or Image=C:\Icons\Myicon.ico, not any random ico or image

$item.SubItems(1).Text = $lsvList1.FocusedItem.SubItems(1).Text
$item.SubItems(2).Text = $lsvList1.FocusedItem.SubItems(2).Text
$item.SubItems(3).Text = $lsvList1.FocusedItem.SubItems(3).Text

EndFunction



tito
(Fresh Scripter)
2018-09-14 06:11 PM
Re: ListView.OnDoubleClick

@Shawn -- Thank you. I've been racking my brain for the correct code syntax to select an item/subitem and pass it to a variable. I'd prefer to just select one subitem. but this gets me further than I got. I created a listview container. added columns. The ListView items are populated with specific attributes from the results of an AD Query.
(using fnLDAPQuery() as the AD Search tool. Author: Christopher Shilt and Contributor Jens Meyer.)

Thanks Shawn and the others that continue to support/contribute to this kix and KixForms forum