2010-02-11 4 views
2

Je me fais une exception quand je veux ajouter des éléments dans mon NodeView:Exception dans Gtk.NodeView.AddNode

Exception dans Gtk # délégué de rappel Remarque: Les applications peuvent utiliser pour GLib.ExceptionManager.UnhandledException gérer l'exception. System.IndexOutOfRangeException: l'index du tableau est hors limites. à Gtk.NodeStore.get_value_cb (Int32 node_idx, Int32 col, GLib.Value & val) [0x00000] à GLib.ExceptionManager.RaiseUnhandledException (System.Exception e, is_terminal Boolean) à Gtk.NodeStore.get_value_cb (Int32 node_idx, Colonne Int32, Valeur ByRef val) à Gtk.Application.gtk_main() à Gtk.Application.Run() à IcePipe.Program.Main (Arguments System.String []) dans/home/tomcatfort/Projects/IcePipe/GUI/Program.cs: ligne 18

Je crée ce code en mono 2.4.2.3. Et j'utilise Gtk #. Vous pouvez télécharger mon code à partir de ce lien: http://tomcatfort.net/priv/IcePipe.tar.gz

Je ne sais pas ce qui cause le problème, je ne trouve rien qui pourrait être le problème.

Voici le code qui lève l'exception:

public MainWindow() : base(Gtk.WindowType.Toplevel) 
{ 
    this.Build(); 
    mContactsNodeStore.AddNode(new Contact("Kutya", new Gdk.Pixbuf("Img/Refresh24x24.png"))); //AddNode(...) throws it. 
} 

Création d'une instance de contact ne provoque pas exception, je l'ai essayé.

Voici comment je l'ai fait l'NodeView:

mContactsNodeStore = new NodeStore(typeof(Contact)); 
mContactsNodeView = new NodeView(mContactsNodeStore); 
mContVBox2.PackStart(mContactsNodeView, true, true, 0); 
mContactsNodeView.AppendColumn("Icon", new CellRendererPixbuf(), "pixbuf", 0); 
mContactsNodeView.AppendColumn("Name", new CellRendererText(), "text", 1); 

Et voici Contact:

[Gtk.TreeNode (ListOnly = true)] //What is this for? 
public class Contact : Gtk.TreeNode, IDisposable 
{ 
    #region Fields and properties 
    [Gtk.TreeNodeValue (Column = 1)] 
    private string pName; 

    /// <summary> 
    /// Gets or sets the name of the contact. 
    /// </summary> 
    public string Name { 
     get {return pName;} 
     protected set {pName = value;} 
    } 

    [Gtk.TreeNodeValue (Column = 0)] 
    private Gdk.Pixbuf pIcon; 

    /// <summary> 
    /// Gets or sets the icon of the contact. 
    /// </summary> 
    public Gdk.Pixbuf Icon { 
     get {return pIcon;} 
     protected set {pIcon = value;} 
    } 
    #endregion 


    #region Constructor adn disposer 
    /// <summary> 
    /// Initialize the contact. 
    /// </summary> 
    public Contact(string aName, Gdk.Pixbuf aIcon) : base() 
    { 
     pName = aName; 
     pIcon = aIcon; 
    } 

    /// <summary> 
    /// Release allocated resources. 
    /// </summary> 
    public void Dispose() 
    { 
     Disposing(this, null); 
    } 
    #endregion 


    #region Events 
    /// <summary> 
    /// Fired when the contact is being disposed. 
    /// </summary> 
    public event EventHandler Disposing; 
    #endregion 
} 
+0

Veuillez ajouter la partie du code où l'exception est renvoyée à votre question. Merci. – Bobby

+0

Le commentaire de Second Bobby. On dirait que vous essayez d'obtenir une ligne qui n'existe pas, mais sans regarder le code, il est difficile de dire ce qui se passe. – seanhodges

Répondre

0

Vous avez 2 champs dans votre classe de contact à la fois définis comme "colonne = 0", donc il est pas de colonne 1.

Essayez de changer votre champ PICON à ceci:

[Gtk.TreeNodeValue (Column = 1)] 
private Gdk.Pixbuf pIcon; 

Cela devrait indiquer à TreeView qu'il devrait avoir 2 colonnes.

This resource peut vous être utile.

+0

Je l'ai corrigé, mais j'ai toujours la même exception. Et j'ai comparé mon code à celui de votre lien, mais je n'arrive toujours pas à trouver le problème. – TomCatFort

0

J'ai juste eu le même problème. Rendre les champs accessibles public au lieu de private a résolu mon problème. Bien sûr, gardez à l'esprit que changer la visibilité en public n'est peut-être pas la meilleure solution, vous pouvez donc l'inclure dans une propriété en lecture seule ou quelque chose comme ça.