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

Checkboxes in Listviews and Treeviews (VB script)

 
Post new topic   Reply to topic    KiXforms Forum Index -> Advanced Scripting
View previous topic :: View next topic  
Author Message
TheDane
KiXforms Novice
KiXforms Novice


Joined: 01 Oct 2007
Posts: 3
Location: Stavanger, Norway

PostPosted: Mon Jan 21, 2008 1:01 pm    Post subject: Checkboxes in Listviews and Treeviews (VB script) Reply with quote

When using checkboxes in either Listviews or treeviews the FocusedItem does not change if I only click inside the checkbox (not the selected row)

An OnClick event is fired when checking a checkbox but I am unable to extract the index for the row the checkbox is on.
Only when I am selecting the row can I get the correct FocusedItem

When checking / unchecking is there any event I can use to extract the index for the row the checkbox is on ...???

I am running on XP - SP2 using kixforms.dll - 2.46.55.0 using ASE as script editor.... Very Happy

The Dane
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 Jan 21, 2008 1:28 pm    Post subject: Reply with quote

the Treeview event to check for is .OnAfterSelect as it contains the selected node as Event Data.

Dunno exactly for ListViews, but maybe check of .FocusedItem property or .SelectedItems collection in combination with the .Checked property ...

I might find the time to make a short sample using KiXtart later today

_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.


Last edited by Jochen on Mon Jan 21, 2008 1:48 pm; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
Jochen
KiXforms Devotee
KiXforms Devotee


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

PostPosted: Mon Jan 21, 2008 1:46 pm    Post subject: Reply with quote

Here is a short Listview sample in KiX that shows the checked items in the form title :

Code:

break on

$s=createobject("Kixtart.System")

$f=$s.Form()
$f.Text="Checked: "

$lv=$f.Controls.Add("ListView")
$lv.Size=$f.Size
$lv.Columns.Count=1
$lv.CheckBoxes=1

for $n=0 to 4
    $_=$lv.Items.Add('Item '+$n)
next

$lv.OnClick = "lv_Click()"


$f.Show

while $f.Visible
    $_=execute($f.DoEvents)
loop

function lv_Click()
    dim $n
    $f.Text = "Checked: "
    for $n = 0 to $lv.Items.Count-1
        if $lv.Items($n).checked
            $f.Text = $f.Text + $n + ' '
        endif
    next
endfunction

_________________
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
Jochen
KiXforms Devotee
KiXforms Devotee


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

PostPosted: Mon Jan 21, 2008 1:54 pm    Post subject: Reply with quote

Even better (handles also Keyboard input)

Code:

break on

$s=createobject("Kixtart.System")

$f=$s.Form()
$f.Text="Checked: "

$lv=$f.Controls.Add("ListView")
$lv.Size=$f.Size
$lv.Columns.Count=1
$lv.CheckBoxes=1

for $n=0 to 4
    $_=$lv.Items.Add('Item '+$n)
next

$lv.OnClick="lv_Click()"
$lv.OnKeyDown="lv_Click()"

$f.Show

while $f.Visible
    $_=execute($f.DoEvents)
loop

function lv_Click()
    dim $n
    $f.Text = "Checked: "
    for $n = 0 to $lv.Items.Count-1
        if $lv.Items($n).checked
            $f.Text = $f.Text + $n + ' '
        endif
    next
endfunction

_________________
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
TheDane
KiXforms Novice
KiXforms Novice


Joined: 01 Oct 2007
Posts: 3
Location: Stavanger, Norway

PostPosted: Mon Jan 21, 2008 2:02 pm    Post subject: Reply with quote

Well..Using FocusedItem or SelectedItem won't help me because the row on which the checkbox is on does NOT get the focus..hence is not added to the SelectedItems collection.

It also seem a bit illogical not add a checked item to the selectedItems when the Multiselect is true.

Getting all the checked items after the user is done "checking" is not prob.
Unless I use a for each loop with SelectedItems..then VB krasjes..
I have added a small section called "Comment out this below lines if the working with SelectedItems do not work"...
Could you possible verify that this is not just my computer...???

Here is som sampel code to play around with..
Code:

'region ScriptForm Designer

'region Constructor

Dim System: Set System = CreateObject("KiXtart.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 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim Form1: Set Form1 = System.Form()
Form1.Size = System.Size(521, 193)
Form1.Text = "Form1"
'~~< ListView1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim ListView1: Set ListView1 = Form1.Controls.ListView
'~~< ListView1.Columns >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim Column1: Set Column1 = ListView1.Columns.Add()
Column1.Text = "ColumnHeader"
Column1.Width = 446
ListView1.Location = System.Point(13, 13)
ListView1.HeaderStyle = 0
ListView1.View = 1
ListView1.Text = "ListView1"
ListView1.Size = System.Size(484, 132)
ListView1.CheckBoxes = True
ListView1.MultiSelect = True
ListView1.OnSelectedIndexChanged = "ListView1OnSelectedIndexChanged( ListView1 )"
ListView1.OnClick = "ListView1OnClick( ListView1 )"
Form1.OnResize = "Form1OnResize( Form1 )"

'endregion

'region Custom Code

'endregion

'region Event Loop

Dim FormEvent

Form1.Visible = True
Do While Form1.Visible
   
   'Capture the event text string
   FormEvent = Form1.DoEvents
   Wscript.echo "Event name : " & FormEvent

   If FormEvent <> "" Then
         
      Execute(FormEvent)
         
   End If
   
Loop

'endregion

'endregion

'region Event Handlers

Function ListView1OnClick( Object )

End Function

Function ListView1OnSelectedIndexChanged( Object )
   
      With Object.FocusedItem
     
         If .Checked Then

            .Checked = False
           
         Else
           
            .Checked = True
   
         End If   
   
      End With

      Dim Item
   
      'Comment out this below lines if the working with SelectedItems do not work...
      If Object.SelectedItems.Count <> 0 Then
   
         For Each Item In Object.SelectedItems
            WScript.Echo "Item text : " & Item.Text
         Next
     
   
End Function

Function Form1OnResize( Object )
   
   
'~~< ListView1.Items >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim ListView1Items1: Set ListView1Items1 = ListView1.Items.Add()
'~~< ListView1Items1.SubItems >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ListView1Items1.Text = "List item 1"
Dim ListView1Items2: Set ListView1Items2 = ListView1.Items.Add()
'~~< ListView1Items2.SubItems >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ListView1Items2.Text = "List item 2"
Dim ListView1Items3: Set ListView1Items3 = ListView1.Items.Add()
'~~< ListView1Items3.SubItems >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ListView1Items3.Text = "List item 3"
   
   
End Function

'endregion


Btw. please notice that the Form1.DoEvents in the Event loop above has been rewritten a bit. With the version 2.46.55 the DoEvents returns 2 events (NOT just one) where one 1 empty and the other is the event text string. The VB script function Execute do NOT like to execute empty strings. Can't understand why..... Laughing
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Advanced Scripting 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