[Gtk-sharp-list] how to search for a value in a ListStore

Radu kenjiru.ro at gmail.com
Wed Jan 31 06:08:21 EST 2007


That's what I was looking for. Thank you for your quick response.

Peter Johanson wrote:
> On Tue, Jan 30, 2007 at 07:28:31PM +0200, Radu wrote:
  > There are basically two ways (there's a third, but it's fairly
> innefficient, so I won't bother):
> 
> 1)
> 
> TreeIter iter;
> 
> if (list.GetIterFirst (out iter)) {
> 	do {
> 		string s = (string)list.GetValue (iter, 1);
> 
> 		if (s == "first string") {
> 			break;
> 		}
> 	} while (list.IterNext (ref iter));
> }
> 
> 2)
> 
> list.Foreach (new TreeModelForeachFunc (SearchForeach));
> 
> bool SearchForeach (TreeModel m, TreePath p, TreeIter i)
> {
> 	string s = (string)m.GetValue (i, 1);
> 
> 	if (s == "my search term") {
> 		found_iter_class_field = i;
> 		return true;
> 	}
> 
> 	return false;
> }
> 
> 
> HTH,
> 
> -pete


More information about the Gtk-sharp-list mailing list