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 Update Items

 
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion
View previous topic :: View next topic  
Author Message
mercury
KiXforms Regular
KiXforms Regular


Joined: 10 Aug 2005
Posts: 50

PostPosted: Tue Dec 20, 2005 10:32 pm    Post subject: ListView Update Items Reply with quote

I am trying to update entries in a listview but am seeing some weird results.
The following code creates a prepopulated listview and some textboxes that change to reflect the currently selected listview item. If you change the text and press the Update button the relevant item/subitems should change.

What happens is the item(0) text field visibly changes straight away but the other subitems appear static. If you then change the selection to another item and back again there is still no change in the list view but the textboxes reflect the new values. If the Update button is pressed twice all the remaining subitems change to refect the new values. Am I doing this the wrong way?

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
$nul = $System.Application.EnableVisualStyles

$Form1 = $System.Form()
$Form1.Left = 272
$Form1.StartPosition = 0  ;FormStartPosition_Manual
$Form1.Size = $System.Size(350,211) ;(Width,Height)
$Form1.Text = "Form1"
$Form1.Top = 250


$ListViewNames = $System.ListView()
$ListViewNames.Left = 10
$ListViewNames.Top = 10
$ListViewNames.Width = 320
$ListViewNames.SelectedIndexChanged = "UDF_ShowDetails()"
$ListViewNames.View = $System.View_Details
$nul = $Form1.Controls.Add($ListViewNames)

$ListViewNamesColumn0 = $ListViewNames.Columns.Add($System.ColumnHeader("First Name",103,$System.HorizontalAlignment_Left))
$ListViewNamesColumn1 = $ListViewNames.Columns.Add($System.ColumnHeader("Last Name",113,$System.HorizontalAlignment_Center))
$ListViewNamesColumn2 = $ListViewNames.Columns.Add($System.ColumnHeader("Age",100,$System.HorizontalAlignment_Right))

$ListViewNamesItem00 = $ListViewNames.Items.Add($System.ListViewItem("Tom"))
$ListViewNamesItem01 = $ListViewNames.Items.Item(0).SubItems.Add($System.ListViewSubItem("Smith"))
$ListViewNamesItem02 = $ListViewNames.Items.Item(0).SubItems.Add($System.ListViewSubItem("20"))

$ListViewNamesItem10 = $ListViewNames.Items.Add($System.ListViewItem("Bob"))
$ListViewNamesItem11 = $ListViewNames.Items.Item(1).SubItems.Add($System.ListViewSubItem("Jones"))
$ListViewNamesItem12 = $ListViewNames.Items.Item(1).SubItems.Add($System.ListViewSubItem("35"))

$ListViewNamesItem20 = $ListViewNames.Items.Add($System.ListViewItem("Sarah"))
$ListViewNamesItem21 = $ListViewNames.Items.Item(2).SubItems.Add($System.ListViewSubItem("Butler"))
$ListViewNamesItem22 = $ListViewNames.Items.Item(2).SubItems.Add($System.ListViewSubItem("32"))


$TextBoxFirstName = $System.TextBox()
$TextBoxFirstName.Left = 10
$TextBoxFirstName.Text = ""
$TextBoxFirstName.Top = 120
$nul = $Form1.Controls.Add($TextBoxFirstName)

$TextBoxLastName = $System.TextBox()
$TextBoxLastName.Left = 120
$TextBoxLastName.Text = ""
$TextBoxLastName.Top = 120
$nul = $Form1.Controls.Add($TextBoxLastName)

$TextBoxAge = $System.TextBox()
$TextBoxAge.Left = 230
$TextBoxAge.Text = ""
$TextBoxAge.Top = 120
$nul = $Form1.Controls.Add($TextBoxAge)

$ButtonUpdate = $System.Button()
$ButtonUpdate.FlatStyle = 3  ;System
$ButtonUpdate.Left = 10
$ButtonUpdate.Text = "Update"
$ButtonUpdate.Top = 150
$ButtonUpdate.Click = "UDF_UpdateListViewEntry()"
$nul = $Form1.Controls.Add($ButtonUpdate)

$Form1.Show  ;Displays the Form



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

Function UDF_ShowDetails()
   
   $TextBoxFirstName.Text = $ListViewNames.SelectedItems.Item(0).Text
   $TextBoxLastName.Text = $ListViewNames.SelectedItems.Item(0).SubItems.Item(1).Text
   $TextBoxAge.Text = $ListViewNames.SelectedItems.Item(0).SubItems.Item(2).Text
   
EndFunction

Function UDF_UpdateListViewEntry()
   
   $ListViewNames.SelectedItems.Item(0).Text = $TextBoxFirstName.Text
   $ListViewNames.SelectedItems.Item(0).SubItems.Item(1).Text = $TextBoxLastName.Text
   $ListViewNames.SelectedItems.Item(0).SubItems.Item(2).Text = $TextBoxAge.Text
   
EndFunction
[/code]
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: Wed Dec 21, 2005 12:41 am    Post subject: Reply with quote

Howdy merc,
I think you are very close, I think your UDF_UpdateListViewEntry() function should have the BeginUpdate/EndUpdate like this:
Code:
Function UDF_UpdateListViewEntry()
   
   $ListViewNames.BeginUpdate
   $ListViewNames.SelectedItems.Item(0).Text = $TextBoxFirstName.Text
   $ListViewNames.SelectedItems.Item(0).SubItems.Item(1).Text = $TextBoxLastName.Text
   $ListViewNames.SelectedItems.Item(0).SubItems.Item(2).Text = $TextBoxAge.Text
   $ListViewNames.EndUpdate
   
EndFunction


but this does not seem to be working, Shawn will have to investigate. For the time being here is a work around:
Code:
Function UDF_UpdateListViewEntry()
   
   $ListViewNames.SelectedItems.Item(0).SubItems.Clear
   $ListViewNames.SelectedItems.Item(0).Text = $TextBoxFirstName.Text
   $= $ListViewNames.SelectedItems.Item(0).SubItems.Add($System.ListViewSubItem($TextBoxLastName.Text))
   $= $ListViewNames.SelectedItems.Item(0).SubItems.Add($System.ListViewSubItem($TextBoxAge.Text))
   
EndFunction

_________________
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: Wed Dec 21, 2005 1:33 am    Post subject: Reply with quote

well, you may not believe this Merc, but you hit (yet another) obscure .net bug ... found some knowledge base on this, but still coding this up in real .net to repro verify ... stay tuned.
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: Wed Dec 21, 2005 2:38 am    Post subject: Reply with quote

merc,
here is another way around it, with the order reversed, it seems to know to redraw the listview control.
Code:
Function UDF_UpdateListViewEntry()
   
   $Index = $ListViewNames.SelectedItems.Item(0).Index
   $ListViewNames.BeginUpdate
   $ListViewNames.Items.Item($Index).SubItems.Item(2).Text = $TextBoxAge.Text
   $ListViewNames.Items.Item($Index).SubItems.Item(1).Text = $TextBoxLastName.Text
   $ListViewNames.Items.Item($Index).Text = $TextBoxFirstName.Text
   $ListViewNames.EndUpdate
   
EndFunction


I think the real key is that the column 0 item is the last in the list.

or if you prefer you could do it with the selecteditems like with the way you started:
Code:
Function UDF_UpdateListViewEntry()
   
   $ListViewNames.BeginUpdate
   $ListViewNames.SelectedItems.Item(0).SubItems.Item(2).Text = $TextBoxAge.Text
   $ListViewNames.SelectedItems.Item(0).SubItems.Item(1).Text = $TextBoxLastName.Text
   $ListViewNames.SelectedItems.Item(0).Text = $TextBoxFirstName.Text
   $ListViewNames.EndUpdate
   
EndFunction


_________________
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: Wed Dec 21, 2005 2:56 am    Post subject: Reply with quote

here is the knowledge base article:

ListViewSubItem Refresh Problems

Think we have a fix for it though.
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Wed Dec 21, 2005 3:22 am    Post subject: Reply with quote

Posted a new development build to address this issue. Check it out and advise.
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: Wed Dec 21, 2005 3:32 am    Post subject: Reply with quote

shawn you da man!
with shawn's new build, your original script works now.

_________________
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
mercury
KiXforms Regular
KiXforms Regular


Joined: 10 Aug 2005
Posts: 50

PostPosted: Wed Dec 21, 2005 10:03 am    Post subject: Reply with quote

Call it a talent or a curse.. If there is a deeply hidden, obscure, esoteric, "face north whilst standing on one leg whistling the national anthem in Swahili" type bug... I'll find it Smile

You guys are the best! Thanks for the quick response.

I tried reversing the order "main item last" in my other code and all when well except where I did not update that item. The work-around was simply to re-assign the original value to force a refresh.
The new build fixes that problem as well Smile

When would one need to use the Refresh or Update method?
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Wed Dec 21, 2005 1:42 pm    Post subject: Reply with quote

Quote:

When would one need to use the Refresh or Update method?


In my estimation, one should never have to use Refresh - only as a last resort when all else fails.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion 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