How do I add new items to a combo or list box?

Q:

How do I add new items to a combo or list box?
----

A:
You could add new items to a combo box (or to a list box) as by adding
new strings to 'Opt' array in the field dictionary. For example:

FieldIterator itr = doc.FieldFind("MyCombo");
if (itr != doc.FieldEnd()) {
  Field f = itr.Current();
  if (f.GetType() == Field.Type.e_choice) {
     Obj field_dict = f.GetSDFObj();
     Obj options_array = field_dict.FindObj("Opt");
     if (options_array == null) {
        options_array = Obj.CreateArray();
        field_dict.Put("Opt", options_array);
     }

     // Add new options...
     options_array.PushBack(Obj.CreateString("Item5"));
     options_array.PushBack(Obj.CreateString("Item6"));
  }
}

The code in the previous post is now out of date, the following code is what should be used now.

Field f = doc.GetField("MyCombo"); if (f != null) { if (f.GetType() == Field.Type.e_choice) { Obj field_dict = f.GetSDFObj(); Obj options_array = field_dict.FindObj("Opt"); if (options_array == null) { options_array = field_dict.PutArray("Opt"); } // Add new options... options_array.PushBackString("Item5"); options_array.PushBackString("Item6"); } }