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

Missunderstanding with ListView sub items...

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


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Thu Jul 26, 2007 4:35 pm    Post subject: Missunderstanding with ListView sub items... Reply with quote

Code:

$BrowseForm = $System.Form()
$BrowseForm.Font = $System.Font("Century Gothic",9,0) ;Regular
$BrowseForm.FormBorderStyle = 1  ;FormBorderStyle_FixedSingle
$BrowseForm.MinimizeBox = 0  ;False
$BrowseForm.MaximizeBox = 0  ;False
$BrowseForm.StartPosition = 1  ;FormStartPosition_CenterScreen
$BrowseForm.Size = $System.Size(900,674) ;(Width,Height)
$BrowseForm.Text = "Browser"
$BrowseForm.Icon = $System.Icon.FromBitmap(my_Icon())

$BrowseLB = $System.ListView()
$BrowseLB.Font = $System.Font("Century Gothic",7,0) ;Regular
$BrowseLB.ItemHeight = 14
$BrowseLB.Left = 0
$BrowseLB.MultiColumn = -1 ;True
$BrowseLB.MultiSelect = 0 ;False
$BrowseLB.SelectionMode = 3  ;MultiExtended
$BrowseLB.Sorted = -1  ;True
$BrowseLB.Top = 20
$BrowseLB.Width = $BrowseForm.Width-4
$BrowseLB.Height = $BrowseForm.Height-24
$BrowseLB.GridLine = "True"
$BrowseLB.FullRowSelect = "True"

$BrowseLB.View = $System.View_Details
$nul = $BrowseForm.Controls.Add($BrowseLB)

$BrowseLBC00 = $BrowseLB.Columns.Add($System.ColumnHeader("Col1",46,$System.HorizontalAlignment_Left))
$BrowseLBC01 = $BrowseLB.Columns.Add($System.ColumnHeader("Col2",52,$System.HorizontalAlignment_Center))
$BrowseLBC02 = $BrowseLB.Columns.Add($System.ColumnHeader("Col3",66,$System.HorizontalAlignment_Right))
$ = ReadinData()
For $R = 1 to $Lines
  $BrowseLBI00 = $BrowseLB.Items.Add($System.ListViewItem($data[1,$R]))
  $BrowseLBI01 = $BrowseLB.Items.Item($R).SubItems.Add($System.ListViewSubItem($data[0,$R]))
  $BrowseLBI02 = $BrowseLB.Items.Item($R).SubItems.Add($System.ListViewSubItem($data[2,$R]))
Next

etc...

I am failing to add the sub item data, mainly because I don't understand where the .Items($R).SubItems which I find in most examples is derrived from. What is Item(#) ? in the middle of the line ?
Currently get only the first column of data.

Also have I set it correctly for complete row select rather than just first column ?

M
Rolling Eyes
________
Volcano vaporizers


Last edited by MACE1 on Fri Feb 18, 2011 5:13 pm; edited 1 time in total
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Thu Jul 26, 2007 4:57 pm    Post subject: Reply with quote

One of the issues here is that the code is indexing from 1 to "n" as its adding - but when a listview adds, the index starts from 0 (zero) not one - so this code is always one listviewitem ahead of itself. Heres is a better way (I think) of handling this:


Code:

For $R = 0 to 10
  $BrowseLBI00 = $BrowseLB.Items.Add($System.ListViewItem("Item"+$R))
  $BrowseLBI01 = $BrowseLBI00.SubItems.Add($System.ListViewSubItem("SubItem1"))
  $BrowseLBI02 = $BrowseLBI00.SubItems.Add($System.ListViewSubItem("SubItem2"))
Next


You add a ListViewItem and save it by name (you dont care about the index) - then, use that item to add its "own" subitems (the second two lines) ... dont have to deal with any indexes. Here's the full code:

Code:

Break On

$System = CreateObject("Kixforms.System")

$BrowseForm = $System.Form()

$BrowseForm.Font = $System.Font("Century Gothic",9,0) ;Regular
$BrowseForm.FormBorderStyle = 1  ;FormBorderStyle_FixedSingle
$BrowseForm.MinimizeBox = 0  ;False
$BrowseForm.MaximizeBox = 0  ;False
$BrowseForm.StartPosition = 1  ;FormStartPosition_CenterScreen
$BrowseForm.Size = $System.Size(900,674) ;(Width,Height)
$BrowseForm.Text = "Browser"
;$BrowseForm.Icon = $System.Icon.FromBitmap(my_Icon())

$BrowseLB = $System.ListView()
$BrowseLB.Font = $System.Font("Century Gothic",7,0) ;Regular
$BrowseLB.ItemHeight = 14
$BrowseLB.Left = 0
$BrowseLB.MultiColumn = -1 ;True
$BrowseLB.MultiSelect = 0 ;False
$BrowseLB.SelectionMode = 3  ;MultiExtended
$BrowseLB.Sorted = -1  ;True
$BrowseLB.Top = 20
$BrowseLB.Width = $BrowseForm.Width-4
$BrowseLB.Height = $BrowseForm.Height-24
$BrowseLB.GridLine = "True"
$BrowseLB.FullRowSelect = "True"

$BrowseLB.View = $System.View_Details

$nul = $BrowseForm.Controls.Add($BrowseLB)

$BrowseLBC00 = $BrowseLB.Columns.Add($System.ColumnHeader("Col1",46,$System.HorizontalAlignment_Left))
$BrowseLBC01 = $BrowseLB.Columns.Add($System.ColumnHeader("Col2",52,$System.HorizontalAlignment_Center))
$BrowseLBC02 = $BrowseLB.Columns.Add($System.ColumnHeader("Col3",66,$System.HorizontalAlignment_Right))

;$ = ReadinData()

For $R = 0 to 10
  $BrowseLBI00 = $BrowseLB.Items.Add($System.ListViewItem("Item"+$R))
  $BrowseLBI01 = $BrowseLBI00.SubItems.Add($System.ListViewSubItem("SubItem1"))
  $BrowseLBI02 = $BrowseLBI00.SubItems.Add($System.ListViewSubItem("SubItem2"))
Next

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

Exit 0
Back to top
View user's profile Send private message
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Thu Jul 26, 2007 8:13 pm    Post subject: Reply with quote

That certainly looks a lot easier. Not sure where the other indexes from the examples I gleened were being used.
Gridview is not showing, but I think select by row is working OK.

I have noted 0 generally equals FALSE but have found 1 and -1 are used for TRUE, again not sure of the root of this logic.

When I plod through kixforms.net.chm I am still after all this time confused how to get at the information you have relayed in a few simple sentances... very frustrating when I find commands which look to be what is desired but can't get the syntax right.

Thanks once again.
Very Happy
M
________
Marijuana


Last edited by MACE1 on Sat Mar 12, 2011 5:35 pm; edited 1 time in total
Back to top
View user's profile Send private message
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Fri Jul 27, 2007 4:09 pm    Post subject: Reply with quote

Confused
This is starting to REALLY get to me.
The expanded version of the script I am using has in fact 8 columns, is initially sorted on column 1 and has row selection enabled.

From the postings on the forum it would appear column sort is probably not defined yet. I have found discussions on identifying which column is selected for a bubble sort but the methodology of sorting the columns eludes me. All I wanted to do was sort according to the column header clicked on as in V2 kixforms.

Having created a large table, I want to be able to pass the row number selected to define the content or pass the content of the entire row to an array on a click event. AS it is I am gettin nothing out of the items !

If anyone can direct me to a working example I would be very very pleased....
________
Satanism, the church of satan forum


Last edited by MACE1 on Fri Feb 18, 2011 5:14 pm; edited 1 time in total
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Fri Jul 27, 2007 6:48 pm    Post subject: Reply with quote

Sadly, automatic column sorting buy header click isn't a feature of .net - one has to code their own "sorter" as a call-back routine and that isn't practical with Kixforms.Net (way too slow).

Me and apronk (Arend) have been working on a solution to this - to enhance the .Net listview to support automatic sorting - we have an idea about adding a generic sorter into the listview - and some code - but it isn't implemented yet.

The best one can do (today) is to sort on the first item (the main ListViewItem) of a row - ascending or descending by string. And the column click one would have to implement (using ColumnHeaderClick)

The Kixforms (v2) ListView is a custom job I wrote myself - that has all these Bells and whistles - but working with .Net one is limited (initially) to only what is available.

This is a good opportunity to get this .Net listview sorting done - maybe over the weekend.
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Sun Jul 29, 2007 12:55 pm    Post subject: Reply with quote

Mace1,
maybe this post will help you, ListView - clicking column header to resort

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Mon Jul 30, 2007 7:57 am    Post subject: Reply with quote

Thanks, I actually incorporated this into the script last week which tells me which column was selected. I am trying to devise a quick enough script to sort the core array and re-display in the listview.
I use an array as follows ARRAY[X,Y] where X= PAGEs and Y= 0 to # entries on the page. A Column sort on the listview is effectivly sorting an entry in Y across pages X.
Bubble sorts work fine on single dimensional arrays, not sure what best to do with this array.
Had played with extracting a Y column to a sub array , sorting it there then using the result to compare to the main array, and display the results in the listview.
VERY slow so am looking for alternatives ...HELP !!!!

Shocked NB: What is the proper way to..
1] Clear a listview of previous content... to Re-display sorted content
I currently use
$BrowseForm.hide
$BrowseForm.dispose
Then re-call the function to build the form.

2] Detect a row selection so whichever sub item is clicked it triggers the correct index number...

Oh yes... I have not been displaying with an indexed construction in the listview as data has come from main array so how do I relate these...I can not gget my head arround the .net index approach.
Its NOT a small order... Exclamation
________
Motorcycle Tires


Last edited by MACE1 on Fri Feb 18, 2011 5:14 pm; edited 1 time in total
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Mon Jul 30, 2007 11:55 am    Post subject: Reply with quote

I think your looking for:
Code:

$Listview.Items.Clear

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Tue Jul 31, 2007 4:26 pm    Post subject: Reply with quote

I have come to the conclusion 'I need to know' when I click on any item in a row the value of its primary item from which all subitems are derrived but I am failing to identify how to do this. From that I could query the primary array to manipulate the data.

Can someone direct me to how to derrive this regardless of which item and subitem in the row is chosen ?

Would I be correct in the assumption that were I to create and populate a listview, with an index, but not actually show the view, I could still use it like my primary array and query its values while not visible?
At the moment I have a large array[page,fields] from which I derrive the listview!
________
Toyota v engine


Last edited by MACE1 on Fri Feb 18, 2011 5:14 pm; edited 1 time in total
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Tue Jul 31, 2007 5:03 pm    Post subject: Reply with quote

to find the column 0 Item.text you would identify a function for the click of the listview:

Code:

$ListView.Click = "ListViewItemClick()"


then create the function:
Code:

Function ListViewItemClick()
   ;do something with the information
   ? $ListView.SelectedItems.Item(0).Text
EndFunction


assuming that you have:
Code:

$ListView.FullRowSelect = -1  ;True


this would work, here is an example:
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

$Form = $System.Form()
$Form.StartPosition = 1  ;FormStartPosition_CenterScreen
$Form.Size = $System.Size(600,500) ;(Width,Height)
$Form.Text = "Form"

$ListView = $System.ListView()
$ListView.ColumnClick = "ListView_ColumnClick(0)"
$ListView.Click = "ListViewItemClick()"
$ListView.Dock = 5  ;Fill
$ListView.FullRowSelect = -1  ;True
$ListView.GridLines = -1  ;True
$ListView.View = $System.View_Details
$nul = $Form.Controls.Add($ListView)

$ListViewColumn0 = $ListView.Columns.Add($System.ColumnHeader("Column 0",100,$System.HorizontalAlignment_Left))
$ListViewColumn1 = $ListView.Columns.Add($System.ColumnHeader("Column 1",100,$System.HorizontalAlignment_Center))
$ListViewColumn2 = $ListView.Columns.Add($System.ColumnHeader("Column 2",100,$System.HorizontalAlignment_Right))

$Col0 = Split("26 17 7 1 4 13 21 22 14 3 2 20 23 10 24 19 11 18 8 9 12 5 6 16 15 25") ; 1-26
$Col1 = Split("Z Q G A D M U V N C B T W J X S K R H I L E F P O Y")                  ; A-Z
$Col2 = Split("1 10 20 26 23 14 6 5 13 24 25 7 4 17 3 8 16 9 19 18 15 22 21 11 12 2") ; 26-1

For $Index = 0 to 25
   $Item = $ListView.Items.Add($System.ListViewItem($Col0[$Index]))
   $Item = $ListView.Items.Item($Index).SubItems.Add($System.ListViewSubItem($Col1[$Index]))
   $Item = $ListView.Items.Item($Index).SubItems.Add($System.ListViewSubItem($Col2[$Index]))
Next

$ButtonPanel = $System.Panel()
$ButtonPanel.BorderStyle = 1  ;FixedSingle
$ButtonPanel.Dock = 1  ;Top
$ButtonPanel.Height = 40
$nul = $Form.Controls.Add($ButtonPanel)

$Button = $System.Button()
$Button.Click = "SortOrder()"
$Button.Left = 10
$Button.Text = "Ascending"
$Button.Top = 10
$nul = $ButtonPanel.Controls.Add($Button)

$Form.Show  ;Displays the Form

While $Form.Visible
   $Nul = Execute($Form.DoEvents())
Loop
Exit 0

Function ListViewItemClick()
   ;do something with the information
   ? $ListView.SelectedItems.Item(0).Text
EndFunction

Function SortOrder()
   If $Order = 0
      $Order = 1
      $Button.Text = "Descending"
      $ListView.ColumnClick = "ListView_ColumnClick(1)"
   Else
      $Order = 0
      $Button.Text = "Ascending"
      $ListView.ColumnClick = "ListView_ColumnClick(0)"
   EndIf
EndFunction

Function ListView_ColumnClick($Order)
   Dim $ItemCount,$ColumnIndex,$TempLen,$Length,$Row,$ItemText,$NextRow,$NextItemText,$Item,$nul
   $ListView.BeginUpdate
   $ItemCount = $ListView.Items.Count - 1
   $ColumnIndex = $System.EventArgs.Column
   For $Row = 0 to $ItemCount
      $TempLen = Len($ListView.Items.Item($Row).SubItems.Item($ColumnIndex).Text)
      If $TempLen > $Length
         $Length = $TempLen
      EndIf
   Next
   For $Row = 0 to $ItemCount
      For $NextRow = $Row + 1 to $ItemCount
         $ItemText = $ListView.Items.Item($Row).SubItems.Item($ColumnIndex).Text
         $NextItemText = $ListView.Items.Item($NextRow).SubItems.Item($ColumnIndex).Text
         If (PadNumbers($NextItemText,$Length) < PadNumbers($ItemText,$Length) And Not $Order) Or (PadNumbers($NextItemText,$Length) > PadNumbers($ItemText,$Length) And $Order)
            $Item = $ListView.Items.Item($NextRow)
            $nul = $ListView.Items.Item($NextRow).Remove
            $nul = $ListView.Items.Insert($Row,$Item)
         EndIf
      Next
   Next
   $ListView.EndUpdate
EndFunction

Function PadNumbers($,$i)
   Dim $g,$h
   For $h = Len($) to $i
      For $g = 0 to 9
         $=Join(Split($,$g),#+$g)
      Next
   Next
   $PadNumbers=$
EndFunction


Quote:

Would I be correct in the assumption that were I to create and populate a listview, with an index, but not actually show the view, I could still use it like my primary array and query its values while not visible?
At the moment I have a large array[page,fields] from which I derrive the listview!


As far as using a control that is not visible (ListView), yes you can do that.

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Tue Jul 31, 2007 6:37 pm    Post subject: Reply with quote

Very Happy
Excelent example, appears to cover my needs, will spend this evening disecting it and see if I can understand what is going on...

You'r a STAR for helping with this, I have so much to learn !
________
HEADSHOP


Last edited by MACE1 on Fri Feb 18, 2011 5:15 pm; edited 1 time in total
Back to top
View user's profile Send private message
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Fri Aug 03, 2007 9:11 am    Post subject: Reply with quote

Crying or Very sad
Elegant solution but not up to the job on a large data set.
8 Columns, Approx 700 rows > 15 minutes to sort.
I think I will have to abandon this function until a 'native' version is available.
It makes the whole ListView approach untenable.

Now Considering whether it would be possible and safe to make a hybrid between Kixforms and Kixforms.net to make this useable as the sort function is widely used. Question
Both reside on the users Machines.
________
Suzuki Madura Specifications
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