diff --git a/src/kits/interface/Layout.cpp b/src/kits/interface/Layout.cpp index 35a09536ac..812d9f2868 100644 --- a/src/kits/interface/Layout.cpp +++ b/src/kits/interface/Layout.cpp @@ -279,14 +279,15 @@ BLayout::IndexOfView(BView* child) const if (child == NULL) return -1; - int itemCount = fItems.CountItems(); + // A BView can have many items, so we just do our best and return the + // index of the first one in this layout. + BView::Private viewPrivate(child); + int32 itemCount = viewPrivate.CountLayoutItems(); for (int32 i = 0; i < itemCount; i++) { - BLayoutItem* item = (BLayoutItem*)fItems.ItemAt(i); - if (item->View() == child && (dynamic_cast(item) - || dynamic_cast(item))) - return i; + BLayoutItem* item = viewPrivate.LayoutItemAt(i); + if (item->Layout() == this) + return IndexOfItem(item); } - return -1; }