Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8685359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:33:04+00:00 2026-06-12T22:33:04+00:00

How do I move a selection up or down in a Treeview? The idea

  • 0

How do I move a selection up or down in a Treeview?

The idea is that I can have an up and down buttons to move the selection up a row or down a row.

My Treeview is using a ListStore. Not sure if that matters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:33:05+00:00Added an answer on June 12, 2026 at 10:33 pm

    First off, I will be using C code as that’s what I’m familiar with. Should you have problems translating it to Python, then say so, and I will do my best to help.

    The class you want to use for this is GtkTreeSelection. Basically, what you do is:

    1. Get the selection object of the view (gtk_tree_view_get_selection)
    2. Get the currently selected GtkTreeIter (gtk_tree_selection_get_selected).
    3. Aquire the next/previous iter (gtk_tree_model_iter_next/previous)
    4. If there is one (ie. if the previous function returned true), make it the currently selected one (gtk_tree_selection_select_iter)

    In my little test program, the callback for the “down” button looked like this:

    static void on_down(GtkWidget *btn, gpointer user_data)
    {
        GtkTreeSelection *sel = GTK_TREE_SELECTION(user_data);
        GtkTreeModel *model;
        GtkTreeIter current;
    
        gtk_tree_selection_get_selected(sel, &model, &current);
        if (gtk_tree_model_iter_next(model, &current))
            gtk_tree_selection_select_iter(sel, &current);
    }
    

    (here is the full program for reference)

    When connecting, I passed the TreeSelection object to the callback.

    Edit: This is how Samuel Taylor translated the above to Python:

    TreeView = Gtk.TreeView()
    list = Gtk.ListStore(str, str)
    TreeView.set_model(list)
    
    def down(widget):
        selection = TreeView.get_selection()
        sel = selection.get_selected()
        if not sel[1] == None:
            next = list.iter_next(sel[1])
            if next:
                selection.select_iter(next)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realize that if you are having a same selection in JComboBox, using up/down
I have 3 drop down selectors using AJAX (first is populated, after selection the
In my GWT program I have a table that has a selected row. I'd
I have a Silverlight 4 app which pulls entities down from a database using
I am using a drop down list as a navigation option to move between
I have a ListBox in single-selection-mode containing some items. I implemented that the user
I have an app that allows the user to move from a list of
To draw a selection rectangle from the mouse down , mouse move then remove
Question: Is there an easy way to sort jList using Up/Down Buttons on jFrame?
I am trying to move some files in python, but they have spaces in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.