[Gtk-sharp-list] what is best approach to update model for TreeView?

Christian Hoff christian_hoff at gmx.net
Fri Mar 27 10:50:26 EDT 2009


danieru wrote:
> So, the questions:
>
> 1. I understand that I should let the GTK main loop thread handle GUI
> changes; I've been doing this with the invoke method, but does this rule
> apply to the model that is tied to the TreeView as well?  Should my queue
> thread ask the GTK loop thread to make all the changes to the model, or can
> the queue thread make the changes and the GTK main loop will auto-notice
> them and update the treeview?
>   
Yes, this rule applies to the model as well. The model can only be 
updated from the Gtk thread.
> 2. In connection with question one, are there any extra steps I need to take
> to notify the GTK main loop?  I've looked through the ListStore methods and
> I'm seeing methods like 'EmitRowChanged', etc. These would seem to imply
> that the GTK main loop won't notice these changes...and maybe that my queue
> thread can change the model, but I'm not sure.
>   
No, these methods in ListStore shall not be called directly. They are 
members of GtkTreeModel, but as we generate that class as a .net 
interface, we cannot place the method code in the interface itself.
> 3. I want to be able to perform actions based on a unique ID in my data
> rows, remove them, update them, etc. What methods/approaches are good for
> this with GTK, both from the user side (e.g. capturing the row that the user
> clicked on), or from the program side (e.g. remove row with unique ID 'x')?
>   
In general it is always a very bad idea to keep the data in two places 
in memory; e. g. in an array your program uses and in the ListStore. If 
you have to store your row data in another internal data structure and 
not just in the ListStore, you can write a custom TreeModel:

http://www.mono-project.com/ImplementingGInterfaces



More information about the Gtk-sharp-list mailing list