// adjust sorted column
if IsColumn and (FSortColumn>=0) then begin // "begin" added
if Between(FSortColumn, FromIndex, ToIndex) then begin
if FSortColumn=FromIndex then
FSortColumn := ToIndex
else
if FromIndex<FSortColumn then
Dec(FSortColumn)
else
Inc(FSortColumn);
end;
end else // added
FSortColumn := -1; // added