gpt4 book ai didi

c# - Gtk.NodeView.AddNode 中的异常

转载 作者:太空宇宙 更新时间:2023-11-03 16:55:25 27 4
gpt4 key购买 nike

当我想将元素添加到我的 NodeView 时出现异常:

Exception in Gtk# callback delegate Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception. System.IndexOutOfRangeException: Array index is out of range. at Gtk.NodeStore.get_value_cb (Int32 node_idx, Int32 col, GLib.Value& val) [0x00000] at GLib.ExceptionManager.RaiseUnhandledException(System.Exception e, Boolean is_terminal) at Gtk.NodeStore.get_value_cb(Int32 node_idx, Int32 col, Value ByRef val) at Gtk.Application.gtk_main() at Gtk.Application.Run() at IcePipe.Program.Main(System.String[] args) in /home/tomcatfort/Projects/IcePipe/GUI/Program.cs:line 18

我在 mono 2.4.2.3 中制作这段代码。我正在使用 Gtk#。您可以从此链接下载我的代码:http://tomcatfort.net/priv/IcePipe.tar.gz

我不知道是什么导致了这个问题,我找不到任何可能是问题的东西。

下面是抛出异常的代码:

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

创建Contact实例不会导致异常,我试过了。

这就是我制作 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);

这是联系方式:

[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
}

最佳答案

您的 Contact 类中有 2 个字段都定义为“Column = 0”,因此没有第 1 列。

尝试将您的 pIcon 字段更改为:

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

这应该指示 TreeView 它应该有 2 列。

This resource可能对你有帮助。

关于c# - Gtk.NodeView.AddNode 中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2243202/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com