[Gtk-sharp-list] Combobox clear and reload
henkdp at mweb.co.za
Fri Oct 10 19:19:11 EDT 2008
Michael Hutchinson wrote:
> On Thu, Oct 9, 2008 at 12:58 PM, henkdp <henk at bbd.co.za> wrote:
>> Good day,
>> I am a total newbie to Monodevelop Stetic and GTK#. :blush: I have
>> high and low on the internet and this forum, don't know if I am looking
>> wrong key words but here is my problem.
>> I want to create a ComboBoxEntry widget with employees in it, I populate
>> with values from the database, nothing fancy and I managed that. However,
>> when a new employee is added I want to clear the ComboBoxEntry and
>> it, I don't just want to append the new value at the bottom.
>> Here, to explain is a snippet of my code loading the ComboboxEntry:
>> protected void LoadEmployeeCombo()
>> //Load the employee details
>> DataTable datatableEmployeeDropDown =
>> foreach (DataRow r in datatableEmployeeDropDown.Rows )
>> string empnumber = r["empnumber"].ToString();
>> string nickname = r["nickname"].ToString();
>> string trim_nickname = nickname.Trim();
>> string surname = r["surname"].ToString();
>> string trim_surname = surname.Trim();
>> string employeeNumberAndName = ( empnumber + " - " +
>> + " " + trim_surname );
>> HTEmpNocomboboxentry.AppendText( employeeNumberAndName );
>> //Add this to the top of the combo entry box for when a new employee
>> is needed
>> HTEmpNocomboboxentry.PrependText("New - type new employee number "
>> As I said nothing fancy and you can see from the code I am a real newbie!
> You may need to delve into the more advanced aspects of the
> TreeView/TreeModel system.
> //create a list store with one column, of type string, and set it to
> be our combo's model
> ListStore model = new ListStore (typeof (string));
> combo.Model = model;
> //create a text renderer and add it to the combo box
> //note that you can pack in multiple renderers, e.g. an icon renderer
> CellRendererText textRenderer = new CellRendererText ();
> combo.PackStart (textRenderer, true);
> //map the "text" property of the renderer to column 0 in the model
> //note that you can map any columns in the model to any properties of
> the renderer
> combo.AddAttribute (textRenderer, "text", 0);
> //add some values to the model
> model.AddValues ("foo");
> //clear the model
> model.Clear ();
> These same principles apply to the TreeView.
> Michael Hutchinson
> Gtk-sharp-list maillist - Gtk-sharp-list at lists.ximian.com
Thank you very much Michael, I tried it and it works. Much appreciated.
Henk du Plessis
View this message in context: http://www.nabble.com/Combobox-clear-and-reload-tp19903032p19927517.html
Sent from the Mono - Gtk# mailing list archive at Nabble.com.
More information about the Gtk-sharp-list