Page 1 of 1 1
Topic Options
#128715 - 2004-10-31 05:33 PM ListView.OnDoubleClick
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
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?

_________________________
I will always look out from behind these eyes...

Top
#128716 - 2004-10-31 05:55 PM Re: ListView.OnDoubleClick
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11161
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#128717 - 2004-10-31 06:16 PM Re: ListView.OnDoubleClick
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Where do u find this ListViewSelectedItemCollection ...
Its not much regading ListViewSelectedItemCollection at Kixforms BBS or Doc...

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


Edited by JazzM (2004-10-31 06:18 PM)
_________________________
I will always look out from behind these eyes...

Top
#128718 - 2004-10-31 06:30 PM Re: ListView.OnDoubleClick
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8609
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



Top
#128719 - 2004-10-31 08:36 PM Re: ListView.OnDoubleClick
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Great Shawn :-)

U R D Best!

happy halloween

_________________________
I will always look out from behind these eyes...

Top
#128720 - 2004-11-01 11:33 AM Re: ListView.OnDoubleClick
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
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
_________________________
I will always look out from behind these eyes...

Top
#128721 - 2004-11-01 02:12 PM Re: ListView.OnDoubleClick
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8609
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



Top
#128722 - 2004-11-20 03:35 PM Re: ListView.OnDoubleClick
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
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


_________________________
I will always look out from behind these eyes...

Top
#128723 - 2004-11-20 04:39 PM Re: ListView.OnDoubleClick
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11161
Loc: Boston, MA, USA
By adding images to the ImageList collection via the ImageCollection.Add method.
_________________________
There are two types of vessels, submarines and targets.

Top
#128724 - 2004-11-20 05:49 PM Re: ListView.OnDoubleClick
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8609
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

Top
#128725 - 2004-11-20 07:44 PM Re: ListView.OnDoubleClick
Jochen Moderator Online   happy
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6296
Loc: Stuttgart, Germany
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
_________________________



Top
#128726 - 2004-11-21 05:09 PM Re: ListView.OnDoubleClick
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
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

_________________________
I will always look out from behind these eyes...

Top
#128727 - 2004-11-21 05:34 PM Re: ListView.OnDoubleClick
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Why do you have an ENDIF in your lsvList1DC() function?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#128728 - 2004-11-21 09:16 PM Re: ListView.OnDoubleClick
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Ahh... why the endif is there½!"# just ignore it...
_________________________
I will always look out from behind these eyes...

Top
#128729 - 2004-11-22 01:44 AM Re: ListView.OnDoubleClick
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11161
Loc: Boston, MA, USA
That's not how it works over here. An ENDIF without corresponding IF will screw up your code.
_________________________
There are two types of vessels, submarines and targets.

Top
#128730 - 2004-11-22 02:25 PM Re: ListView.OnDoubleClick
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
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

_________________________
I will always look out from behind these eyes...

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Chris S., Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
4 registered (Jochen, AndreLuiz, Flavien, Arend_) and 206 anonymous users online.
Newest Members
Sjaak, Biybucket, Markus1961, Ian231, kixnewbie12
17480 Registered Users

Generated in 0.077 seconds in which 0.029 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org