Well you seem to know which section of code it's happening from, time to start some real programming and debug that code. Setup some breakpoints and go through line by line until you find the problem. We are not going to be able to solve the problem for you, especially with the information given.
Quick Edit: Also if your going to use code salvaged from the internet, I would suggest first learning what the code does. The tutorial you are using is ok (source :
http://www.dreamincode.net/forums/topic/230524-c-tile-engine-from-scratch-part-1/) but just make sure you know what is going on in the code after it's copy pasted