I know the pants are a darker grey than the ties. But would that still be okay? Or should I just go for black to be safe?
It's for a formal dressed birthday party/dinner
Either tie works. Another dark tie with some color would be better, e.g, navy, burgundy, bottle green, purple, or even brown if you will be wearing brown shoes.
If the sweater is never coming off, then either tie would work, but the gray tie would look better, since the sweater dramatically mitigates the view of the grey tie rendering it acceptable.
This would also be true of a brighter colored tie such as red, orange, yellow, or bright green or blue.
If the sweater might come off, wear the black tie or one of the dark ties suggested above.
If you have a charcoal tie with some color in the form of a bright neat pattern that doesn't conflict with the shirt pattern or even a charcoal bright repp pattern tie, either would work.
Since it's a "formal dressed birthday party/dinner", I suggest going with a lighter grey v-neck sweater the color of your grey tie and a black or navy sport coat, instead of the darker sweater, then wear the black tie or another dark tie such a recommended above.
You should, in fact, wear some form jacket and not just a sweater, since the event is someone's idea of "formal". Even a black leather bomber over the outfit you intend to wear, would be a better choice than sweater alone.