我必须使用 Gtk DnD 排序的树视图。DnD 没有问题,但我不明白如何对节点进行排序。我正在尝试使用Gtk::TreeStore.reorder(parent, new_order)
,但我不明白出了什么问题。
从我的代码中提取:
@store = Gtk::TreeStore.new(String, String, String, String)
@tree =Gtk::TreeView.new(@store)
@tree.set_headers_visible(false)
column = Gtk::TreeViewColumn.new
renderer = Gtk::CellRendererPixbuf.new
column.pack_start(renderer, false)
column.add_attribute(renderer, 'stock_id', 2)
renderer = Gtk::CellRendererText.new
column.pack_start(renderer, true)
column.add_attribute(renderer, "text", 1)
@tree.append_column(column)
@tree.enable_tree_lines=true
@tree.selection.mode = Gtk::SELECTION_SINGLE
def fct_Treeview_orderIter(treeviewIter, store)
arrResult=Array.new
arrTmp=Array.new
hNodes=Hash.new
hResult=Hash.new
nbiter=treeviewIter.n_children
p "nb children=#{nbiter}"
(0..nbiter-1).each do |index|
child_iter=treeviewIter.nth_child(index)
hNodes[index]=child_iter[1]
#fct_Treeview_orderIter(child_iter, store)
end
arrTmp=hNodes.to_a.sort do |a, b|
a[1] <=> b[1]
end
arrResult=arrTmp.collect { |entry| [entry[0].to_i] }.flatten
store.reorder(treeviewIter, arrResult)
end
对于列表存储,我有与此示例相同的错误消息...
有人能帮助我吗 ?