Array / TreeView question

Questions regarding syntax

Re: Array / TreeView question

Postby GaryVass » Thu Sep 09, 2010 3:14 am

PapaWinni,

I looked at the code in the zip file, and read through the German posts, but those did not seem to apply to what I am trying to do. I need to change the item that is being viewed in the treeview window, and pass that changed value to a Mysql database.

So far, I am unable to do this.
GaryVass
 
Posts: 65
Joined: Mon Nov 19, 2007 6:53 am

Re: Array / TreeView question

Postby pappawinni » Thu Sep 09, 2010 5:15 pm

Hi Gary,
sorry, seems I do not really understand your problem.
You say: "I need to change the item that is being viewed in the treeview window and pass the change.."
Does this mean . you want your program storing data if the user changes an item in the treeview...or.. ?
And what is then the problem ?
You do not get an event...or the event does not tell you what changed .. or ?

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

Re: Array / TreeView question

Postby GaryVass » Thu Sep 09, 2010 5:52 pm

Yes, I want my program to record the change so I can then pass it on to my databse.

Basicaly, once a user changes the value of an item in the treeview, I need to know what the new value is AND save that new value in the old value's place. I can't seem to figure out how to do this. The treeview.data caption, and other options seem to record some data, but hey are a string of numbers and not the 'text' or other value that the user put into the treeview.
GaryVass
 
Posts: 65
Joined: Mon Nov 19, 2007 6:53 am

Re: Array / TreeView question

Postby Slowdown » Thu Sep 09, 2010 7:31 pm

Hi GaryVass,
Hope i understand you problem.
Can you use,
Code: Select all
Dim id As Integer
Dim Dummy as Integer


Sub Form_OnOpen()
  SetColumsTreeView
  GenerateData
End Sub

Private Sub SetColumsTreeView() 
  TreeView1.SetColumnCount(3)
  TreeView1.SetColumnWidth(0, 150)
  TreeView1.SetColumnWidth(1, 150)
  TreeView1.SetColumnWidth(2, 150)
  TreeView1.setHeaderLabel ("Column-1", 0)
  TreeView1.setHeaderLabel ("Column-2", 1)
  TreeView1.setHeaderLabel ("Column-3", 2)
End Sub

Private Sub GenerateData()
  Dim FirstLus as Integer
  Dim SecondLus As Integer
 
  For FirstLus = 1 to 10
    Dim id As Integer = TreeView1.appendChild ("")
    DataToTreeView ("", "P1 " & FirstLus, "P2 " & FirstLus, "P3 " & FirstLus, id)       
  Next   
End Sub

Private Sub TreeView1_OnClick(X As Integer, Y As Integer, GlobalX As Integer, GlobalY As Integer, LeftButton As Boolean, RightButton As Boolean, MidButton As Boolean)
  Dim Id As Integer = TreeView1.CurrentItem()
  Dim NewStr as String
 
  if LeftButton = true then
    MsgBox ("Caption " & TreeView1.Caption(Id, 0) & "   Column " & TreeView1.CurrentColumn())
  end if
  If RightButton = True Then
    NewStr = InputBox ("New Value")
    TreeView1.SetCaption(Id, TreeView1.CurrentColumn(), NewStr)
  End If
End Sub
 
Private Sub DataToTreeView (Icon as String, ColumnOne as String, ColumnTwo as String, ColumnTree as String, MyId as Integer)
'  Dim id As Integer = TreeView1.appendChild ("")
 
  TreeView1.SetIcon(MyId, 0, Icon)
  TreeView1.SetCaption(MyId, 0, ColumnOne)
  TreeView1.SetCaption(MyId, 1, ColumnTwo)
  TreeView1.SetCaption(MyId, 2, ColumnTree)
  TreeView1.Setcaption(MyId, 3, MyId)
End Sub
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: Array / TreeView question

Postby pappawinni » Thu Sep 09, 2010 8:07 pm

Hi Gary,
Sorry, but the user can - if editable - edit the CAPTION in the treeview.
If you know the ID for a certain Item in the treeview you can read the Caption of each column.

? treeview1.caption(ID, column)
(column 0 means first column...)

I do not know how you organize the data in your database to know how to write to treeview
but I think you need to know the relation between your datasets and the ID in the treeview to write data back.

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

Re: Array / TreeView question

Postby pappawinni » Thu Sep 09, 2010 10:13 pm

Hi Gary,

probably it can help you if you know the path for a certain item.
For this purpose I created 2 functions, one to get the indices and another to get the IDs from top level down to the item.
Both returning a string like this "level1;level2;..."
From this string you could e.g. also read the depth (level) of the child in the tree.
The "treeview1" is hardcoded, so if the name of your treeview is different you need to change.
If you want to modify or rename the functions, watch that both functions are recursive, so do not forget to also rename or modify the self-call.

Code: Select all
Private function GetItemIdPath(idChild As Integer, optional BelowIdParent as integer) as string
  Dim IndexChild As Integer
  Dim strOut as String
  Dim idP as Integer
  Dim idC as integer
   
  if isMissing(BelowIdParent) then
    idP = TreeView1.InvisibleRootItem()
  else
    idP = BelowIdParent
  endif

  IndexChild = TreeView1.ChildCount(idP)   
  do until IndexChild <= 0
    idC = TreeView1.Child(idP, IndexChild)   
    If TreeView1.ChildCount(idC) > 0 Then
      strOut = GetItemIdPath(idChild,idC) 
      if strOut <> "" then
        return  idC & ";" &strOut
        exit function
      end if
    end if
    if idC=idChild then
      strOut = idC
      return strOut
      exit function
    end if
    IndexChild = IndexChild - 1
  loop 
  return ""
End function

Private function GetItemIndexPath(idChild As Integer, optional BelowIdParent as integer) as string
  Dim IndexChild As Integer
  Dim strOut as String
  Dim idP as Integer
  Dim idC as integer
   
  if isMissing(BelowIdParent) then
    idP = TreeView1.InvisibleRootItem()
  else
    idP = BelowIdParent
  endif

  IndexChild = TreeView1.ChildCount(idP)   
  do until IndexChild <= 0
    idC = TreeView1.Child(idP, IndexChild)   
    If TreeView1.ChildCount(idC) > 0 Then
      strOut = GetItemIndexPath(idChild,idC) 
      if strOut <> "" then
        return  IndexChild & ";" &strOut
        exit function
      end if
    end if
    if idC = idChild then
      strOut = IndexChild
      return strOut
      exit function
    end if
    IndexChild = IndexChild - 1
  loop 
  return ""
End function
Pappa makes everything what otherwise none likes :)
pappawinni
 
Posts: 192
Joined: Tue Jan 19, 2010 11:27 pm
Location: Germany

Re: Array / TreeView question

Postby GaryVass » Fri Sep 10, 2010 12:13 am

thanks Papawinni,

I used your code, and can now see the data for each item, but it is the item before or after the row that I want....but I am getting close.
GaryVass
 
Posts: 65
Joined: Mon Nov 19, 2007 6:53 am

Re: Array / TreeView question

Postby GaryVass » Sun Sep 12, 2010 7:47 pm

Well, I can see why everyone was confused by my questions.... It seems that the code does not work on the Linux version, but does work on the windows version of Kbasic.

In windows I seem to be able return the data that I am looking for when ever I am done editing it by hitting return. But in Linux, it does not retrieve the data until you move to another row, and then it gives you the data that is contained in that row and not the data that was edited.
GaryVass
 
Posts: 65
Joined: Mon Nov 19, 2007 6:53 am

Re: Array / TreeView question

Postby berndnoetscher » Mon Sep 13, 2010 12:51 pm

GaryVass wrote:Well, I can see why everyone was confused by my questions.... It seems that the code does not work on the Linux version, but does work on the windows version of Kbasic.

In windows I seem to be able return the data that I am looking for when ever I am done editing it by hitting return. But in Linux, it does not retrieve the data until you move to another row, and then it gives you the data that is contained in that row and not the data that was edited.


Mhmm.... that's very unlikely, because there is no source code difference in this case. Could you please post the relevant code snippet working on windows and not working on linux. Thanks in advance.
berndnoetscher
Site Admin
 
Posts: 1059
Joined: Tue Sep 25, 2007 9:37 am

Re: Array / TreeView question

Postby GaryVass » Mon Sep 13, 2010 3:56 pm

Bernd,

I tried copying the code from my windows machine to my linux machine, and it does now work. Not sure why, as I had copied the code orginally form the linux machine to the windows one.

I had made a few minor changes... perhaps I fixed a typo without realizing it and that made the difference??

Anyway, you are correct, it does work on both systems. Wish I knew what I changed.
GaryVass
 
Posts: 65
Joined: Mon Nov 19, 2007 6:53 am

Previous

Return to Coding Questions

cron