Just to add to what boudino has said...you should run it through the debugger and inspect the contents of 'SelectedItems' and 'SubItems' at runtime. They may not be what you expect. If there is any chance those collections could be empty you should put a test around access to the values (e.g. using an 'if' statement...)