Discussion:
[Gtk-sharp-list] ComboBox
Evgeny Pirogov
2006-01-03 12:58:01 UTC
Permalink
Hello. Happy New Year!

I need simple example for Gtk.ComboBox usage as DropDownList (value only set
from list, no write).

Thanks.
heat sink
2006-01-03 13:32:56 UTC
Permalink
Post by Evgeny Pirogov
Hello. Happy New Year!
I need simple example for Gtk.ComboBox usage as DropDownList (value only
set from list, no write).
Check Monodoc I think what you are looking for should be in the sample code
in the overview section. It's also located in the web version of the
documentation at http://www.go-mono.com/docs/ under Gnome
Libraries->Gtk->ComboBox Class. Just in case you cannot access the web
documentation (but somehow able to read email...), or access/build Monodoc,
I've pasted the sample code from said documentation below...

using System;
using Gtk;

class ComboBoxSample
{
static void Main ()
{
new ComboBoxSample ();
}

ComboBoxSample ()
{
Application.Init ();

Window win = new Window ("ComboBoxSample");
win.DeleteEvent += new DeleteEventHandler (OnWinDelete);

ComboBox combo = ComboBox.NewText ();
for (int i = 0; i < 5; i ++)
combo.AppendText ("item " + i);
combo.Changed += new EventHandler (OnComboBoxChanged);

win.Add (combo);

win.ShowAll ();
Application.Run ();
}

void OnComboBoxChanged (object o, EventArgs args)
{
ComboBox combo = o as ComboBox;
if (o == null)
return;

TreeIter iter;

if (combo.GetActiveIter (out iter))
Console.WriteLine ((string) combo.Model.GetValue (iter, 0));
}

void OnWinDelete (object obj, DeleteEventArgs args)
{
Application.Quit ();
}
}

Thanks.
Post by Evgeny Pirogov
_______________________________________________
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
Happy Hacking!

--
Nick Granado
Mariano Benedettini
2006-01-03 13:47:25 UTC
Permalink
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.
Post by Evgeny Pirogov
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
***@ad-net.us
hemant kumar
2006-01-03 23:05:13 UTC
Permalink
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<small>Any ideas, how to create custom widget using GDK.-Sharp...<br>
<br>
<br>
<br>
With Regards<br>
Hemant<br>
</small>
</body>
</html>
Wolfgang Mauer
2006-01-03 19:34:49 UTC
Permalink
Hi,
take a look at
http://svn.myrealbox.com/viewcvs/trunk/gtk-sharp/sample/CustomWidget.cs
Post by hemant kumar
GDK.-Sharp...
Loading...