int findItem (int hFirstItem, int index) { if (hFirstItem == 0) return 0; if (hFirstItem == hFirstIndexOf) { if (index == 0) { lastIndexOf = 0; return hLastIndexOf = hFirstIndexOf; } if (lastIndexOf == index) return hLastIndexOf; if (lastIndexOf - 1 == index) { --lastIndexOf; return hLastIndexOf = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PREVIOUS, hLastIndexOf); } if (lastIndexOf + 1 == index) { lastIndexOf++; return hLastIndexOf = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hLastIndexOf); } if (index < lastIndexOf) { int previousIndex = lastIndexOf - 1; int hPrevItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PREVIOUS, hLastIndexOf); while (hPrevItem != 0 && index < previousIndex) { hPrevItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PREVIOUS, hPrevItem); --previousIndex; } if (index == previousIndex) { lastIndexOf = previousIndex; return hLastIndexOf = hPrevItem; } } else { int nextIndex = lastIndexOf + 1; int hNextItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hLastIndexOf); while (hNextItem != 0 && nextIndex < index) { hNextItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hNextItem); nextIndex++; } if (index == nextIndex) { lastIndexOf = nextIndex; return hLastIndexOf = hNextItem; } } return 0;
Widget findItem (int id) { TVITEM tvItem = new TVITEM (); tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM; tvItem.hItem = id; if (OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem) != 0) { return _getItem (tvItem.hItem, tvItem.lParam);
int findItem (int hFirstItem, int index) {	if (hFirstItem == 0) return 0;	if (hFirstItem == hFirstIndexOf) {		if (index == 0) {			lastIndexOf = 0;			return hLastIndexOf = hFirstIndexOf;		}		if (lastIndexOf == index) return hLastIndexOf;		if (lastIndexOf - 1 == index) {			--lastIndexOf;			return hLastIndexOf = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PREVIOUS, hLastIndexOf);		}		if (lastIndexOf + 1 == index) {			lastIndexOf++;			return hLastIndexOf = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hLastIndexOf);		}		if (index < lastIndexOf) {			int previousIndex = lastIndexOf - 1;			int hPrevItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PREVIOUS, hLastIndexOf);			while (hPrevItem != 0 && index < previousIndex) {				hPrevItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PREVIOUS, hPrevItem);				--previousIndex;			}			if (index == previousIndex) {				lastIndexOf = previousIndex;				return hLastIndexOf = hPrevItem;			}		} else {			int nextIndex = lastIndexOf + 1;			int hNextItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hLastIndexOf);			while (hNextItem != 0 && nextIndex < index) {				hNextItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hNextItem);				nextIndex++;			}			if (index == nextIndex) {				lastIndexOf = nextIndex;				return hLastIndexOf = hNextItem;			}		}		return 0;	}	int nextIndex = 0, hNextItem = hFirstItem;	while (hNextItem != 0 && nextIndex < index) {		hNextItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hNextItem);		nextIndex++;	}	if (index == nextIndex) {		lastIndexOf = nextIndex;		hFirstIndexOf = hFirstItem;		return hLastIndexOf = hNextItem;	}	return 0;}