Rust: Access the value of Gtk 3 TreeView iter

less than 1 minute read

For a project I am learning Gtk 3 together with the Rust language.

I started with a simple GUI which contains a TreeView and updates a label when an item is activated. The internet is sadly not full of helpful examples, so here you have one if you are trying to do the same.

The provided example is the base for it, so I will only highlight the relevant code from the connect_changed function.

let left_selection = left_tree.get_selection();
left_selection.connect_changed(move |tree_selection| {
    let (left_model, iter) = tree_selection.get_selected().unwrap();
    let mut path = left_model.get_path(&iter).unwrap();

    let value = left_model.get_value(&iter, 0).get::().unwrap();

Tags: ,