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

ListView - clicking column header to resort?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion
View previous topic :: View next topic  
Author Message
masken
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 14 Mar 2003
Posts: 202
Location: Gothenburg, Sweden

PostPosted: Fri Feb 02, 2007 3:56 pm    Post subject: ListView - clicking column header to resort? Reply with quote

I want a listview where I can resort per-column, so that the content gets re-sorted per-row. Is this possible?

Also, how do I highlight certain rows by it's content? (ie, make a button like "mark all entries beginning with "a").
Back to top
View user's profile Send private message MSN Messenger
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat Feb 03, 2007 1:54 am    Post subject: Reply with quote

Here's a small example of selecting items in a listview...

Code:

Break On

$System = CreateObject("Kixforms.System")

$Form = $System.Form()
$Form.ClientWidth = 640
$Form.ClientHeight = 480
$Form.Text = "PhoneBook"

$MainMenu = $System.MainMenu

$FileMenu = $MainMenu.MenuItems.Add($System.MenuItem("File"))

$ExitMenu = $FileMenu.MenuItems.Add($System.MenuItem("Exit"))
$ExitMenu.Click = "ExitClick()"

$SelectMenu = $MainMenu.MenuItems.Add($System.MenuItem("Select"))

$SelectAddressMenu = $SelectMenu.MenuItems.Add($System.MenuItem("Address"))

$SelectAddress1Menu = $SelectAddressMenu.MenuItems.Add($System.MenuItem("Begins with '1'"))
$SelectAddress1Menu.Click = "SelectAddress1_Click()"

$SelectAddress2Menu = $SelectAddressMenu.MenuItems.Add($System.MenuItem("Begins with '5'"))
$SelectAddress2Menu.Click = "SelectAddress2_Click()"

$= $SelectMenu.MenuItems.Add($System.MenuItem("-"))

$SelectClearMenu = $SelectMenu.MenuItems.Add($System.MenuItem("Clear"))
$SelectClearMenu.Click = "SelectClear_Click()"

$SortMenu = $MainMenu.MenuItems.Add($System.MenuItem("Sort"))

$Form.Menu = $MainMenu

$ListView = $Form.Controls.Add($System.ListView())
$ListView.Dock = $System.DockStyle_Fill
$ListView.View = $System.View_Details
$ListView.FullRowSelect = 1

$NameColumn = $ListView.Columns.Add($System.ColumnHeader("Name"))
$AddressColumn = $ListView.Columns.Add($System.ColumnHeader("Address"))
$PhoneColumn = $ListView.Columns.Add($System.ColumnHeader("Phone"))

PopulateListView()

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

Exit 0

Function ExitClick()
 quit
EndFunction

Function PopulateListView()

 Dim $i

 $ListView.Items.Clear

 For $i = 1 to 20

  $NameItem = $ListView.Items.Add($System.ListViewItem())
  $NameItem.Text = "John " + $i

  $AddressItem = $NameItem.SubItems.Add($System.ListViewSubItem())
  $AddressItem.Text = "" + (RND(900)+99) + " Maple Street"

  $PhoneItem = $NameItem.SubItems.Add($System.ListViewSubItem())
  $PhoneItem.Text = "(" + (RND(900)+99) + ") " + (RND(900)+99) + "-" + (RND(9000)+999)

 Next

 $NameColumn.Width = -1
 $AddressColumn.Width = -1
 $PhoneColumn.Width = -1

EndFunction

Function SelectAddress1_Click()

 $ListView.SelectedItems.Clear

 For Each $Item In $ListView.Items
  If Left($Item.SubItems.Item(1).Text,1) = "1"
   $Item.Selected = 1
  Endif
 Next

EndFunction

Function SelectAddress2_Click()

 $ListView.SelectedItems.Clear

 For Each $Item In $ListView.Items
  If Left($Item.SubItems.Item(1).Text,1) = "5"
   $Item.Selected = 1
  Endif
 Next

EndFunction

Function SelectClear_Click()

 $ListView.SelectedItems.Clear

EndFunction
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat Feb 03, 2007 2:36 am    Post subject: Reply with quote

ok, in terms of the Column Clicking - Im going to enhance the ListView to support the ColumnClick event. Once done, we can talk further.
Back to top
View user's profile Send private message
masken
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 14 Mar 2003
Posts: 202
Location: Gothenburg, Sweden

PostPosted: Sun Feb 04, 2007 1:56 pm    Post subject: Reply with quote

Ah, really nice, thanks! Smile

Yeah, kixforms classic had this is some manner, would be really useful I think.
Back to top
View user's profile Send private message MSN Messenger
masken
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 14 Mar 2003
Posts: 202
Location: Gothenburg, Sweden

PostPosted: Wed Feb 07, 2007 9:02 pm    Post subject: Reply with quote

Another (newbie) question, how do you actually decide which column which data goes into?

Below you've just used "SubItems.Add" twice, will it increment one step automatically? How do you set an Item by it's column name?

Shawn wrote:
Here's a small example of selecting items in a listview...

Code:

 For $i = 1 to 20

  $NameItem = $ListView.Items.Add($System.ListViewItem())
  $NameItem.Text = "John " + $i

  $AddressItem = $NameItem.SubItems.Add($System.ListViewSubItem())
  $AddressItem.Text = "" + (RND(900)+99) + " Maple Street"

  $PhoneItem = $NameItem.SubItems.Add($System.ListViewSubItem())
  $PhoneItem.Text = "(" + (RND(900)+99) + ") " + (RND(900)+99) + "-" + (RND(9000)+999)

 Next
Back to top
View user's profile Send private message MSN Messenger
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Thu Feb 08, 2007 12:47 am    Post subject: Reply with quote

Yeah your right, when you "add" a subitem to an item, the assumption is that your moving from left to right incrementing as you go.

To set a value at a particular column, here's one way to do it. Lets say you wanted to set the Address value of the 10th item in the list.

$ListView.Items.Item(10).SubItems.Item($AddressColumn.Index).Text = "Whatever"

Would be nice if one could just use a string somewhere, like "Address", but .Net doesn't have anything like that, for columns anyways.


Last edited by Shawn on Thu Feb 08, 2007 1:07 am; 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 Feb 08, 2007 12:59 am    Post subject: Reply with quote

Heres a modified version of that script that demonstrates the importance of what your asking (changing a column based on some value other than a hard-coded column index) - column indexes can change - the user can re-arrange them if you let them ...

This scripts enables ColumnReorder, and I added a new menu item "Edit" and "Clear Name" or "Clear Address" item.

First, select a row then clear the address. Then move the address column before the name column - or after the phone column - just left-click-drag and drop. Then try the edit->clear again - it still works because the column object index dynamically change with the move..

Code:

Break On

$System = CreateObject("Kixforms.System")

$Form = $System.Form()
$Form.ClientWidth = 640
$Form.ClientHeight = 480
$Form.Text = "PhoneBook"

$MainMenu = $System.MainMenu

$FileMenu = $MainMenu.MenuItems.Add($System.MenuItem("File"))

$ExitMenu = $FileMenu.MenuItems.Add($System.MenuItem("Exit"))
$ExitMenu.Click = "ExitClick()"

$EditMenu = $MainMenu.MenuItems.Add($System.MenuItem("Edit"))

$ClearMenu = $EditMenu.MenuItems.Add($System.MenuItem("Clear"))

$ClearNameMenu = $ClearMenu.MenuItems.Add($System.MenuItem("Name"))
$ClearNameMenu.Click = "ClearName_Click()"

$ClearAddressMenu = $ClearMenu.MenuItems.Add($System.MenuItem("Address"))
$ClearAddressMenu.Click = "ClearAddress_Click()"

$SelectMenu = $MainMenu.MenuItems.Add($System.MenuItem("Select"))

$SelectAddressMenu = $SelectMenu.MenuItems.Add($System.MenuItem("Address"))

$SelectAddress1Menu = $SelectAddressMenu.MenuItems.Add($System.MenuItem("Begins with '1'"))
$SelectAddress1Menu.Click = "SelectAddress1_Click()"

$SelectAddress2Menu = $SelectAddressMenu.MenuItems.Add($System.MenuItem("Begins with '5'"))
$SelectAddress2Menu.Click = "SelectAddress2_Click()"

$= $SelectMenu.MenuItems.Add($System.MenuItem("-"))

$SelectClearMenu = $SelectMenu.MenuItems.Add($System.MenuItem("Clear"))
$SelectClearMenu.Click = "SelectClear_Click()"

$SortMenu = $MainMenu.MenuItems.Add($System.MenuItem("Sort"))

$Form.Menu = $MainMenu

$ListView = $Form.Controls.Add($System.ListView())
$ListView.Dock = $System.DockStyle_Fill
$ListView.View = $System.View_Details
$ListView.FullRowSelect = 1
$ListView.AllowColumnReorder = 1

$NameColumn = $ListView.Columns.Add($System.ColumnHeader("Name"))
$AddressColumn = $ListView.Columns.Add($System.ColumnHeader("Address"))
$PhoneColumn = $ListView.Columns.Add($System.ColumnHeader("Phone"))

PopulateListView()

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

Exit 0

Function ExitClick()
 quit
EndFunction

Function PopulateListView()

 Dim $i

 $ListView.Items.Clear

 For $i = 1 to 20

  $NameItem = $ListView.Items.Add($System.ListViewItem())
  $NameItem.Text = "John " + $i

  $AddressItem = $NameItem.SubItems.Add($System.ListViewSubItem())
  $AddressItem.Text = "" + (RND(900)+99) + " Maple Street"

  $PhoneItem = $NameItem.SubItems.Add($System.ListViewSubItem())
  $PhoneItem.Text = "(" + (RND(900)+99) + ") " + (RND(900)+99) + "-" + (RND(9000)+999)

  $ListView.Items.Item(0).SubItems.Item($AddressColumn.Index).Text = "Whatever"

 Next

 $NameColumn.Width = -1
 $AddressColumn.Width = -1
 $PhoneColumn.Width = -1

EndFunction

Function SelectAddress1_Click()

 $ListView.SelectedItems.Clear

 For Each $Item In $ListView.Items
  If Left($Item.SubItems.Item(1).Text,1) = "1"
   $Item.Selected = 1
  Endif
 Next

EndFunction

Function SelectAddress2_Click()

 $ListView.SelectedItems.Clear

 For Each $Item In $ListView.Items
  If Left($Item.SubItems.Item(1).Text,1) = "5"
   $Item.Selected = 1
  Endif
 Next

EndFunction

Function SelectClear_Click()

 $ListView.SelectedItems.Clear

EndFunction

Function ClearName_Click()

 If $ListView.FocusedItem.Index = -1
  Return
 Endif

 $ListView.FocusedItem.SubItems.Item($NameColumn.Index).Text = ""

EndFunction

Function ClearAddress_Click()

 If $ListView.FocusedItem.Index = -1
  Return
 Endif

 $ListView.FocusedItem.SubItems.Item($AddressColumn.Index).Text = ""

EndFunction

Back to top
View user's profile Send private message
masken
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 14 Mar 2003
Posts: 202
Location: Gothenburg, Sweden

PostPosted: Thu Feb 08, 2007 9:02 pm    Post subject: Reply with quote

Yeah, both that and the fact that its easier to refer to when scripting, and that you might not want to have to "wander through" all columns to update one of them.

Nice, coming a bit further with my script here hehe Smile
Back to top
View user's profile Send private message MSN Messenger
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Thu Feb 08, 2007 11:17 pm    Post subject: Reply with quote

One of the things you may be wondering is ... why cant one say this:

$ListView.Items(0).Text = "Text"
$ListView.Columns(0).Text = "Name"

instead one has to say this:

$ListView.Items.Item(0).Text = "Text"
$ListView.Columns.Item(0).Text = "Name"

Having to specify that extra ".Item" is so annoying in my opinion. The reason is that .Net COM Automation dropped support that syntax. It still bothers me to this day - its so damn non-intuitive.
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: Fri Feb 09, 2007 12:40 am    Post subject: Reply with quote

Also, to read Multiple SubItems in Multiple Coulmns:
Code:

For $Row = 0 to $ListView.Items.Count
   For $Column = 0 to $ListView.Items.Item($Row).SubItems.Count-1
      $Item = $ListView.Items.Item($Row).SubItems.Item($Column).Text
      ? $Item
   Next
Next

In addition, once the Items and SubItems exist, they can be altered like this:
Code:

$ListView.Items.Item($Row).SubItems.Item($Column).Text = "Text"

_________________
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
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Fri Feb 09, 2007 2:35 am    Post subject: Reply with quote

This listview sorting thingy really has me thinking. If you've ever seen the code for how to sort a listview in vb.net - you can appreciate how difficult and convoluted it is. It doesn't translate into a scriptable COM language very well at all.

It involves creating a "sorting object", then registering it as a callback object. Not very friendly. Not giving-up though. Will have to think of an easier (read: custom/scriptable) interface.

Any suggestions welcome.
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: Fri Feb 09, 2007 4:21 am    Post subject: Reply with quote

Shawn,
If the ColumnHeader had a Click event I think I could write a Function to sort that column ascending/descending, and sort the rest of the columns accordingly.

_________________
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
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Fri Feb 09, 2007 4:15 pm    Post subject: Reply with quote

Ok I'll take you up on that offer. Will post a new build shortly that supports the ListView.ColumnClick event.
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 Feb 09, 2007 5:08 pm    Post subject: Reply with quote

Ok, the new version is posted. It works like this:

Setup the event:

Code:

$ListView.ColumnClick = "ListView_ColumnClick()"


In the event, the $System.EventArgs property returns a value of type ColumnClickEventArgs. This object contains a property called Column that is the index of the clicked-column, like so:

Code:

Function ListView_ColumnClick()

 ?"Column Index = " + $System.EventArgs.Column

EndFunction
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: Fri Feb 09, 2007 5:25 pm    Post subject: Reply with quote

Great i will start hacking away at this, Thanks Shawn
_________________
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
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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