Array / TreeView question

Questions regarding syntax

Array / TreeView question

Postby GaryVass » Mon Aug 09, 2010 9:46 pm

I am trying to code a form that will allow the user to review data that is in a mysql database and change a boolean field (ignorit). If ignorit is changed to yes, then later code will ignore that line in the database.

But, first I need to display the data. I have generated the following code, and it works to the point where I am trying to display the array with the treeview and then I get an error.... any ideas?

--- code section ----

Dim recno as integer
Dim tRecno as Integer
Dim I as Integer
dim id as Integer
Dim tId as Integer
Dim DataLine As Array = New Array()

TreeView1.Show()
TreeView1.SetHeaderLabel("Transaction ID", 0)
TreeView1.SetHeaderLabel("Date",1)
TreeView1.SetHeaderLabel("Account",2)
TreeView1.SetHeaderLabel("Transaction",3)
TreeView1.SetHeaderLabel("Ticker",4)
TreeView1.SetHeaderLabel("Amount",5)
TreeView1.SetHeaderLabel("Shares",6)
TreeView1.SetHeaderLabel("Posted",7)
TreeView1.SetHeaderLabel("Ignore",8)
TreeView1.SetColumnWidth(0, 400)
TreeView1.RootIsDecorated = False

strSql = "SELECT * FROM postings;"
rslt = Query.Run(strSql)

sRecordsId = Records.Open(gsDatabase, strSql)
recno = Records.Length(sRecordsId)
tRecno = Recno


for I = 1 to 50
If gsDatabase then
if sRecordsId then
DataLine{I, "ID"} = Records.Value(tRecno, "ID")
DataLine{I, "Date"} = Records.Value(tRecno, "date")
DataLine{I, "AccountNo"} = Records.Value(tRecno, "accountno")
DataLine{I, "Transact"} = Records.Value(tRecno, "transact")
DataLine{I, "Ticker"} = Records.Value(tRecno, "ticker")
DataLine{I, "Amount"} = Records.Value(tRecno, "amount")
DataLine{I, "Shares"} = Records.Value(tRecno, "shares")
DataLine{I, "Posted"} = Records.Value(tRecno, "posted")
DataLine{I, "Ignoreit"} = Records.Value(tRecno, "ignorit")
End If
End If
tRecno = tRecno - 1
Next I


id = TreeView1.AppendChild("")
tId = Dateline{I,"ID"}
TreeView1.SetCaption(id, 0, tId)
' TreeView1.SetCaption(id, 1, Dateline{I,"Date"})
GaryVass
 
Posts: 65
Joined: Mon Nov 19, 2007 6:53 am

Re: Array / TreeView question

Postby Henning » Mon Aug 09, 2010 10:55 pm

Code: Select all
sRecordsId = Records.Open(gsDatabase, strSql)
If sRecordsId Then
   If Records.First(sRecordsId) Then
      recno = Records.Length(sRecordsId)
      tRecno = Recno
   End If
End If

If recno > 0 then
 Do
   I = I + 1
   DataLine{I, "ID"} = Records.Value(sRecordsId, "ID")
   DataLine{I, "Date"} = Records.Value(sRecordsId, "date")
   DataLine{I, "AccountNo"} = Records.Value(sRecordsId, "accountno")
   DataLine{I, "Transact"} = Records.Value(sRecordsId, "transact")
   DataLine{I, "Ticker"} = Records.Value(sRecordsId, "ticker")
   DataLine{I, "Amount"} = Records.Value(sRecordsId, "amount")
   DataLine{I, "Shares"} = Records.Value(sRecordsId, "shares")
   DataLine{I, "Posted"} = Records.Value(sRecordsId, "posted")
   DataLine{I, "Ignoreit"} = Records.Value(sRecordsId, "ignorit")

   If I >= 50 then Exit Loop   'if you want to limit to 50 records
 Loop While Records.Next(sRecordsId)
End If


Air code, hope it works, or at least you get going

/Henning
Henning
 
Posts: 262
Joined: Mon Feb 09, 2009 12:03 am
Location: Sweden

Re: Array / TreeView question

Postby GaryVass » Tue Aug 10, 2010 1:41 pm

Thanks Henning...

I was able to make it work from looking over your example.

Now I have another question...

I don't see in the examples, or by searching the manual online how to edit the data displayed in the treeview. I want to be able to edit one or more data items and then save those back to the mysql database. Is this possible?
GaryVass
 
Posts: 65
Joined: Mon Nov 19, 2007 6:53 am

Re: Array / TreeView question

Postby berndnoetscher » Mon Aug 16, 2010 5:38 pm

GaryVass wrote:Thanks Henning...

I was able to make it work from looking over your example.

Now I have another question...

I don't see in the examples, or by searching the manual online how to edit the data displayed in the treeview. I want to be able to edit one or more data items and then save those back to the mysql database. Is this possible?


If I got you right, to allow the user to change the items (ItemIsEditable) you need to set the items with

http://www.kbasic.com/doku.php?id=treeview#setflag
berndnoetscher
Site Admin
 
Posts: 1059
Joined: Tue Sep 25, 2007 9:37 am

Re: Array / TreeView question

Postby GaryVass » Thu Aug 19, 2010 5:01 am

Ok,

I have looked at the referenced section, and have tried to add it to my code. Before I added anything to the code, I could select a row /item but not change it. After adding the code all of the items are grayed and I can NOT select or change them. The code is below (note: I have tried adding / alternating "itemisselectiable" with "itemisenabled" but this does not seem to change anything). Any ideas? Also, I am not sure I am using the ID column corectly. I have trred putting numbers in there just to see if worked on any part of the treeview output, but it resulted in a crash of the program.

--- begin code -------
Do
I = I + 1
id = TreeView1.AppendChild("")
DataLine{I, "ID"} = Records.Value(sRecordsId, "ID")
TreeView1.SetCaption(id, 0, DataLine{I, "ID"})
DataLine{I, "Date"} = Records.Value(sRecordsId, "date")
TreeView1.SetCaption(id, 1, DataLine{I, "Date"})
DataLine{I, "AccountNo"} = Records.Value(sRecordsId, "accountno")
TreeView1.SetCaption(id, 2, DataLine{I, "AccountNo"})
DataLine{I, "Transact"} = Records.Value(sRecordsId, "transact")
TreeView1.SetCaption(id, 3, DataLine{I, "Transact"})
DataLine{I, "Ticker"} = Records.Value(sRecordsId, "ticker")
TreeView1.SetCaption(id, 4, DataLine{I, "Ticker"})
DataLine{I, "Amount"} = Records.Value(sRecordsId, "amount")
TreeView1.SetCaption(id, 5, DataLine{I, "Amount"})
DataLine{I, "Shares"} = Records.Value(sRecordsId, "shares")
TreeView1.SetCaption(id, 6, DataLine{I, "Shares"})
DataLine{I, "Posted"} = Records.Value(sRecordsId, "posted")
TreeView1.SetCaption(id, 7, DataLine{I, "Posted"})
DataLine{I, "Ignoreit"} = Records.Value(sRecordsId, "ignorit")
TreeView1.SetCaption(id, 8, DataLine{I, "Ignoreit"})
TreeView1.SetFlag(id,"ItemIsSelectable")
TreeView1.SetFlag(id,"ItemIsEditable")


If I >= 1000 then Exit Loop 'if you want to limit to 50 records
Loop While Records.Previous(sRecordsId)

---- end code section ----
GaryVass
 
Posts: 65
Joined: Mon Nov 19, 2007 6:53 am

Re: Array / TreeView question

Postby berndnoetscher » Thu Aug 19, 2010 5:36 am

You need to set all flags at once.

Code: Select all
TreeView1.SetFlag(id,"ItemIsSelectable;ItemIsEditable")
berndnoetscher
Site Admin
 
Posts: 1059
Joined: Tue Sep 25, 2007 9:37 am

Re: Array / TreeView question

Postby GaryVass » Wed Sep 08, 2010 3:30 am

Bernd,

Ok, i am able to modify the item in the treeview, but I don't understand how to record that change. I see the OnCurrentItemChanged(IdCurrent As Integer, IdPrevious As Integer) property, but I don't have any idea on how to use it.

For example, in my code for the treeview I have:

TreeView1.SetFlag(id,"ItemIsEnabled;ItemIsSelectable;ItemIsEditable")
DataLine{I, "Ignoreit"} = Records.Value(sRecordsId, "ignore")
TreeView1.SetCaption(id, 8, DataLine{I, "Ignoreit"})

When the item 'ignore' is changed, I want to be able to save it back to the mysql database as the new value (preferably, it should only be changeable from YES to NO). How do I catch the change event, and move it to a variable that I can write back to the mysql database?
GaryVass
 
Posts: 65
Joined: Mon Nov 19, 2007 6:53 am

Re: Array / TreeView question

Postby berndnoetscher » Wed Sep 08, 2010 8:23 am

GaryVass wrote:Bernd,

Ok, i am able to modify the item in the treeview, but I don't understand how to record that change. I see the OnCurrentItemChanged(IdCurrent As Integer, IdPrevious As Integer) property, but I don't have any idea on how to use it.

For example, in my code for the treeview I have:

TreeView1.SetFlag(id,"ItemIsEnabled;ItemIsSelectable;ItemIsEditable")
DataLine{I, "Ignoreit"} = Records.Value(sRecordsId, "ignore")
TreeView1.SetCaption(id, 8, DataLine{I, "Ignoreit"})

When the item 'ignore' is changed, I want to be able to save it back to the mysql database as the new value (preferably, it should only be changeable from YES to NO). How do I catch the change event, and move it to a variable that I can write back to the mysql database?


I guess, you need to use Sub OnItemChanged(Id As Integer, Column As Integer)

http://www.kbasic.com/doku.php?id=treev ... temchanged

Should popup whenever you change an item:
Code: Select all
Sub TreeView1_OnItemChanged(Id As Integer, Column As Integer)
  MsgBox(Id)
End Sub
berndnoetscher
Site Admin
 
Posts: 1059
Joined: Tue Sep 25, 2007 9:37 am

Re: Array / TreeView question

Postby GaryVass » Wed Sep 08, 2010 5:56 pm

Bernd,

Ok, I can capture that an item is changed, and I can change the value. However, how do I read those changes and place them into a variable?

I have tried the following code (among others) and only get a string of numbers each time, similar to a recordID number, but not the actual value of what is typed into the Treeview control.

Sub TreeView1_OnCurrentItemchanged(Id As Integer, Column As Integer)
Dim WhatColumn as String
if chkEditReady.value= TRUE then
' print
If Column = 7 then WhatColumn = "IgnoreIt"
Print Id, Column, WhatColumn, Treeview1.ItemAt(1, 8)

end if
GaryVass
 
Posts: 65
Joined: Mon Nov 19, 2007 6:53 am

Re: Array / TreeView question

Postby pappawinni » Wed Sep 08, 2010 11:21 pm

Hi Gary,

try
? TreeView1.Caption(ID, Column)

PMan and me tested a bit how to work with treeview.
See thread "TreeView - TopLevelItem" in German Forum.
There PMan also placed some Examples as Zip.

/Winni
Pappa makes everything what otherwise none likes :)
pappawinni
 
Posts: 192
Joined: Tue Jan 19, 2010 11:27 pm
Location: Germany

Next

Return to Coding Questions

cron