#include ONCE "window9.bi"

function FindItemListBox( iGadget as long , sFindString as string , iStartPos as long = -1) as long export
	
	dim as GtkListStore ptr liststore
	
	dim as GtkTreeIter iter
	
	dim as Long iIndex
	
	dim as Long iRet
	
	dim as zstring ptr item_s	
	
	dim as Hwnd listbox = GadgetId(iGadget)	
	
	liststore = cast(any ptr , gtk_tree_view_get_model(cast(any ptr,listbox)))	
	
	iRet = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(liststore), @iter)
	
	while iRet
		
		if iStartPos  = -1 orelse iIndex >= iStartPos then
			
			gtk_tree_model_get(GTK_TREE_MODEL(liststore), @iter, 1, @item_s,  -1)
			
			if *item_s = sFindString then
				
				dim as GtkTreeSelection ptr selection = gtk_tree_view_get_selection (cast(any ptr,listbox))
			
				dim as GtkTreePath ptr path = gtk_tree_path_new_from_indices(iIndex, -1)

				gtk_tree_selection_select_path(selection, path)

				gtk_tree_path_free(path)				
				
				function = iIndex
				
				exit while
				
			EndIf
			
		endif
		
		iIndex += 1
		
		iRet = gtk_tree_model_iter_next (GTK_TREE_MODEL(liststore), @iter)
		
	Wend	

End Function