Comments (8)
The new TreeView checks your implementation of the TreeItem.ChildCount method to determine if the item is expandable. Depending on how you populate your model, it may be necessary to notify the TreeView about new items by calling TreeModelBase.PublishItemsReset (if you embed TreeModelBase in your model), or publish the event yourself and pass the parent item (or nil if roots are to be reset) as parameter.
TreeModel has a LazyPopulation method, that controls how a TreeView populates its internal items. So far I have only tested the lazy case. Maybe the eager case (default with TreeModelBase) isn't working yet.
Anyway, see the filebrowser example for how it can be done.
from walk.
Whoops, just noticed you asked how it can be done without having children. I guess that isn't supported with the new TreeView. If your motivation for doing this is lazy initialization, my first reply should help.
from walk.
Well, I was using the dummy child to handle this problem.
Your comment are very useful, thank you!
from walk.
TreeModelBase.PublishItemsReset
failed with none nil parent when i want to dynamically populate the treeitem child contents.
After item.children appended new contents, I've tried TreeModelBase.PublishItemsReset(item)
and TreeModelBase.PublishItemsReset(item.Parent())
in the handler attached to treeview.ItemExpanded()
, but both failed (crash my program with the output below).
I found only TreeModelBase.PublishItemsReset(nil)
works as i've tried.
C:/Go/src/pkg/runtime/proc.c:1443
C:/Go/src/pkg/runtime/runtime.c:128
C:/Go/src/pkg/runtime/thread_windows.c:276
E:/repos/libs/gopkgs/src/github.com/lxn/walk/treeview.go:388
E:/repos/libs/gopkgs/src/github.com/lxn/walk/container.go:258
E:/repos/libs/gopkgs/src/github.com/lxn/walk/widget.go:1369
C:/Go/src/pkg/runtime/cgocall.c:210
C:/Go/src/pkg/runtime/asm_386.s:473
C:/Go/src/pkg/runtime/asm_386.s:377
C:/Go/src/pkg/runtime/cgocall.c:135
C:/Go/src/pkg/runtime/zsyscall_windows_386.c:97
e:/repos/libs/gopkgs/src/github.com/lxn/go-winapi/user32.go:1487
E:/repos/libs/gopkgs/src/github.com/lxn/walk/widget.go:1467
E:/repos/libs/gopkgs/src/github.com/lxn/walk/treeview.go:432
E:/repos/libs/gopkgs/src/github.com/lxn/walk/widget.go:1369
C:/Go/src/pkg/runtime/cgocall.c:210
C:/Go/src/pkg/runtime/asm_386.s:473
C:/Go/src/pkg/runtime/asm_386.s:377
C:/Go/src/pkg/runtime/cgocall.c:135
C:/Go/src/pkg/runtime/zsyscall_windows_386.c:97
e:/repos/libs/gopkgs/src/github.com/lxn/go-winapi/user32.go:1727
E:/repos/libs/gopkgs/src/github.com/lxn/walk/toplevelwindow.go:119
E:/repos/libs/gopkgs/src/github.com/lxn/walk/dialog.go:219
from walk.
Ok, so you just want lazy initialization.
You should do the same as the filebrowser example:
- Return true from your implementation of TreeModel.LazyPopulation.
- In your implementation(s) of TreeItem.ChildCount check if the children of that item have been initialized.
- If they haven't been initialized, initialize them inside ChildCount and return the number of children.
The TreeView then should take care of everything else and only ever ask for one level of items if you expand an item.
Of course the crash problem should be fixed anyway.
Thanks for your feedback!
from walk.
Yes, I've tried lazy initialization following the filebrowser example, Just as Step 2 and 3 required.
But it's obviously an synchronous process when creating of the child items and returning the item count in the TreeItem.ChildCount
function.
My situation demanding an asynchronous population of the child items, which regards the item expanding click as a trigger to fetch all the content from a remote server. But my communication with the server is asynchronous so i
can only be sure the child items would be fetched, but surely after the TreeItem.ChildCount
's being called.
Well, i have't found a solution yet. Any suggestion?
from walk.
Please try again with the latest changes.
from walk.
Well, thank you!
Your works are really appreciated!
from walk.
Related Issues (20)
- GUI display bug caused by switching monitor screens
- May I have some methods to run the UI with go run xxxx\main.go
- What is the browser kernel for walk webview,chrome or others HOT 4
- Fix grammar errors in README.md
- ListBox.OnCurrentIndexChanged in GroupBox ineffective HOT 1
- 握手失败 HOT 1
- [BUG] Crash when trying to resize the control. HOT 1
- Can‘t use UPX compression HOT 5
- RGBA
- LinkLabel and LinkActivated HOT 1
- How do a get buttons not to take the focus?
- 为组件设置半透明遮罩,可接收点击事件,能实现吗?
- 托盘图标问题
- [ComboBox]OnCurrentIndexChanged:连续触发三次
- Some problems with the dialog.Run() function at Run time
- How to make a square PushButton or a PushButton that height greater than width
- selectbox shall be support?
- Updating GUI by changing the model directly
- LineEdit doesn't receive OnTextChanged event when inside a GroupBox
- TextLabel component text selection?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from walk.