When blue light is shined through a diffraction grating it bends less than a longer wavelength, let's say red light. The shorter the wavelength the less it is bent by diffraction. When the same procedure is performed by passing the light through a medium, let's say glass, the opposite is true. The blue light bends more than the red. Shorter wavelengths bend more. It's interesting to me that they are not just different, but that they are the exact opposite. Why is this? Thanks for addressing this question.
Deflection angle due to a diffraction grating depends on the spacing between the grating lines, and not on the index of the grating (assuming air-grating-air). Longer wavelengths are deflected through larger angles by a diffraction grating.
On the other hand, when light is refracted by a prism, the deflection angle depends on the refractive index of the medium, and refractive index for each wavelength depends on the electronic and quantum properties of the medium. In most glasses the index decreases as wavelength increases in the visible ranges, so the deflection angle (assuming air-prism-air) decreases with increasing wavelength. But there are exceptions. See for example Anomalous Dispersion. In the narrow portions of the spectrum where the index increases with increasing wavelength, the deflection angle from a prism will increase with increasing wavelength. So, though it's usually true in refraction that "shorter wavelengths bend more", it's not always true.