Placing generated list into drop-down on custom menu

buuut the problem is that the list of elements is outside the ul of
the menu in itself.

I think part of the problem might be that wp_list_categories() is in echo-mode by default so $latestpost is always empty.

Please try it with these parameters instead:

// Get the categories
$latestpost = wp_list_categories( array(
  'orderby'    => name,
  'show_count' => 0,
  'exclude'    => 3,
  'title_li'   => "",
  'echo'       => 0,
) );

You can see the default arguments of wp_list_categories() here in the Codex.

The problem with your code example is also that the output of wp_list_categories() is an HTML string, not an array. So this part: $latestpost[0]->ID has no meaning when $latestpost is an (empty) string.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)