この例では動作します:
module gtkd_combobox;
// Compile: ldc -w main.d `pkg-config --cflags --libs gtkd-3`
import std.stdio, core.stdc.stdlib;
import gtk.Builder;
import gtk.Main, gtk.Window, gtk.Button, gtk.ComboBox, gtk.Widget;
import gtk.TreeIter, gtk.TreeModel, gtk.TreeModelIF;
import gtk.ListStore, gtk.CellRendererText;
void on_click_btn_test(ComboBox *cbbox){
TreeIter iter;
TreeModelIF model;
string item;
cbbox.getActiveIter(iter);
model = cbbox.getModel();
item = model.getValueString(iter, 2); // Get value from column 2 (extra data)
writeln(item);
}
void main(string[] args) {
Main.init(args);
Builder g = new Builder();
g.addFromFile("vista.glade");
// Widgets from glade file "vista.glade":
Window w = cast(Window)g.getObject("window1");
w.setDefaultSize(350, 200);
w.setTitle("Gtkd Combobox example");
Button btn_test = cast(Button)g.getObject("btn_test");
ComboBox cbo = cast(ComboBox)g.getObject("cbo_test");
// Actions:
w.addOnHide(delegate void(Widget aux){ Main.quit(); });
btn_test.addOnClicked(delegate void(Button aux){ on_click_btn_test(&cbo); });
// Combo Items:
ListStore store;
store = new ListStore([GType.INT, GType.STRING, GType.STRING]);
TreeIter iter1 = store.createIter();
TreeIter iter2 = store.createIter();
store.setValue(iter1, 0, 0); // iter, column=0, value=0
store.setValue(iter1, 1, "Item 1"); // iter, column=1, value="Item 1"
store.setValue(iter1, 2, "Extra data 1"); // iter, column=2, value="Extra data 1"
store.setValue(iter2, 0, 1);
store.setValue(iter2, 1, "Item 2");
store.setValue(iter2, 2, "Extra data 2");
cbo.setModel(store);
CellRendererText col = new CellRendererText();
cbo.packStart(col, true);
cbo.addAttribute(col, "text", 1);
cbo.setActive(0);
w.showAll();
Main.run();
}