Replace
if (dtgAllIngdetTerminals.Columns["TerminalID"].HeaderText == "TerminalID")
with
if (dtgAllIngdetTerminals.Columns["TerminalID"].Index == e.ColumnIndex)
If your problem is solved you may accept and vote the solution, otherwise post your queries, so that other users can know
PES