The best solution is to remove him from the attention. Before you get to Grandma's house, explain what behavior will be acceptable and what will not. Tell your son that making poor behavior choices will result in time out in Grandma's bedroom, or in the den, or wherever works. Be sure to let Grandma know ahead of time and agree on the place for time out. When you see your son's behavior begin to escalate, remind him once of the rule, then follow through consistently.
If time out away from the group does not help, leave. Let Grandma or your friends know ahead of time that you are working on a positive behavior plan with your son and explain that you may have to leave early if his behavior is not appropriate.
You can do the same thing when you have guests at your house. Talk with your son beforehand and identify the place where he will have time out. If time out doesn't work at home, be ready to ask your guests to leave and invite them to come again another time.
Be sure to tie some positives to this plan as well. Let your son know that appropriate behavior at Grandma's will earn extra computer time or a walk around the block just with you. Follow through consistently with both the consequences and the rewards.