[Gtk-sharp-list] ComboBox
Mariano Benedettini
mbenedettini at ad-net.us
Tue Jan 3 08:47:25 EST 2006
Hello,
Here are two functions, the first of them populates a ComboBox using as
source an ArrayList (two columns, data and text displayed) to build a
ListStore that is used as model on the ComboBox.
The second function is an example that populates three ComboBoxes that
display a date.
private void ComboBoxPopulate(ComboBox comboBox, ArrayList alValuesList )
{
comboBox.Clear();
// types of ListStore columns are taken from alValuesList
ListStore listStore = new Gtk.ListStore(
((object[])alValuesList[0])[0].GetType(),
((object[])alValuesList[0])[1].GetType());
comboBox.Model = listStore;
CellRendererText text = new CellRendererText();
comboBox.PackStart(text, false);
comboBox.AddAttribute(text, "text", 1);
foreach (object[] oaValue in alValuesList)
{
listStore.AppendValues(oaValue[0], oaValue[1]);
}
TreeIter iter;
if (listStore.GetIterFirst (out iter))
{
comboBox.SetActiveIter (iter);
}
}
private void PopulateComboDayMonthYear(ComboBox cbDay, ComboBox
cbMonth, ComboBox cbYear)
{
ArrayList alDays = new ArrayList();
for (int i = 1; i<32; i++)
{
object[] values = {i, i.ToString() };
alDays.Add(values);
}
ArrayList alMonths = new ArrayList();
for (int i = 1; i<13; i++)
{
object[] values = {i,
System.Globalization.DateTimeFormatInfo.CurrentInfo.GetMonthName(i) };
alMonths.Add(values);
}
ArrayList alYears = new ArrayList();
for (int i = DateTime.Now.Year - 95; i < DateTime.Now.Year - 4; i++)
{
object[] values = {i, i.ToString() };
alYears.Add(values);
}
ComboBoxPopulate(cbDay, alDays);
ComboBoxPopulate(cbMonth, alMonths);
ComboBoxPopulate(cbYear, alYears);
}
HTH :-)
Mariano.
Evgeny Pirogov wrote:
> Hello. Happy New Year!
>
> I need simple example for Gtk.ComboBox usage as DropDownList (value only
> set from list, no write).
>
> Thanks.
>
>
--
Mariano Benedettini
Ad Network SA
mbenedettini at ad-net.us
More information about the Gtk-sharp-list
mailing list