[Fwd: [Gtk-sharp-list] ComboBox AppendText and Active]

Daniel Morgan danielmorgan at verizon.net
Mon Jun 27 20:45:57 EDT 2005


Hmmm... There is no ActiveText property for me in gtk# 1.9.5 I'm using.
Am I using something wrong here?

I had to create a class with static methods to do what I wanted.   I 
would subclass, but I could not figure how how to get a subclassed 
instance using Combo.NewText.

namespace Mono.Data.SqlSharp.GtkSharp
{
    using System;
    using GLib;
    using Gtk;

    public class ComboHelper : ComboBox
    {
        public static ComboBox NewComboBox ()
        {
            return ComboBox.NewText ();
        }

        public static string GetActiveText(ComboBox cbox)
        {
            if (cbox.Active < 0)
                return "";

            TreeIter iter;
            cbox.GetActiveIter (out iter);
            string cvalue = ((ListStore) cbox.Model).GetValue (iter, 
0).ToString();
            return cvalue;
        }

        public static bool SetActiveText (ComboBox cbox, string text)
        {
            // returns true if found, false if not found

            string tvalue;
            TreeIter iter;
            ListStore store = (ListStore) cbox.Model;

            store.IterChildren (out iter);
            tvalue  = store.GetValue (iter, 0).ToString();
            if (tvalue.Equals (text)) {
                cbox.SetActiveIter (iter);
                return true;
            }
            else {
                bool found = store.IterNext (ref iter);
                while (found == true) {
                    tvalue = store.GetValue (iter, 0).ToString();
                    if (tvalue.Equals (text)) {
                        cbox.SetActiveIter (iter);
                        return true;
                    }
                    else
                        found = store.IterNext (ref iter);
                }
            }

            return false; // not found
        }
    }
}


Mike Kestner wrote:

>On Sat, 2005-06-25 at 20:34 -0400, Daniel Morgan wrote:
>  
>
>>Here is a customization we could use:
>>    
>>
>
>It's fine to post patches to the list for comment, but please also open
>a bug report and attach them in bugzilla to ensure they don't get
>forgotten in the mailing list archives.
>
>FWIW, I'm less excited about returning the index from SetActiveText than
>I was about the original suggestion for AppendText.  Since there is
>already an ActiveText {get;} , it would be nicer to add this
>functionality as a setter to the prop without the index return.
>
>  
>



More information about the Gtk-sharp-list mailing list