I haven't noticed that you use strings in the second column of the ListStore  and I supposed they where integers

in your case you should change

(int)comboBoxStore.GetValue(ti,1)!=2

for

(string)comboBoxStore.GetValue(ti,1)!="2"



Regards

On 6/20/05, Ricard Rosson Llobet <[EMAIL PROTECTED]> wrote:
Hi. When I have to set an item in a Combo box I do the following:

First I have to know which TreeIter is containing the value I want to set. If I don't know that TreeIter, then I have to search it by hand doing the following:

TreeIter ti;
comboBoxStore.GetIterFirst(out ti)
do
{
if ((int)comboBoxStore.GetValue(ti,1)==2 /*The value I look for*/ )
 break;

}while (comboBoxStore.IterNext(ref ti))

//This loop doesn't check if a value has been found so I will check if the last TreeIter has the value I look for
if ((int)comboBoxStore.GetValue(ti,1)!=2 /*The value I look for*/ )
{
 //Haven't found the value in the TreeStore
}

once I know The TreeIter I set it as the active TreeIter in the ComboBox:

cbFiltro.SetActiveIter(ti);

if I don't want to search the TreeIter I have to know it beforehand saving it somewhere:

TreeIter[] ti=new TreeIter[3];
ti[0]=comboBoxStore.AppendValues("Option #1", "1");
ti[1]=comboBoxStore.AppendValues("Option #2", "2");
ti[2]=comboBoxStore.AppendValues("Option #3", "3");

(...)

cbFiltro.SetActiveIter(ti[1]);


I suppose this should work for you too.









On 6/19/05, Paulinho <[EMAIL PROTECTED] > wrote:
Hi all,

I need to set a item in ComboBox, How i do that ?

In Web i just make this:
myCombo.SelectedValue = "2" , automatically myCombo show me "Description
of Option #2"
sorry i'm novice in GTK# client applications


my code:

CellRendererText descricao = new CellRendererText ();
CellRendererText id          = new CellRendererText ();

comboBoxStore = new ListStore (typeof (string), typeof (string));
cbFiltro.Model = comboBoxStore;

cbFiltro.PackStart (descricao, false);

cbFiltro.AddAttribute (descricao, "text"  , 0);

comboBoxStore.AppendValues("Option #1", "1");
comboBoxStore.AppendValues ("Option #2", "2");
comboBoxStore.AppendValues("Option #3", "3");

...
...

string mySelection = "2";

???


How to set the row of ListStore or ComboBox using a value into variable
"mySelection" ?


Magalhaes

/* Sorry my english */
_______________________________________________
Gtk-sharp-list maillist  -   [email protected]
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list


_______________________________________________
Gtk-sharp-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Reply via email to