Why was David happy when their grain and wine increased?
Rashi (7): I do not envy them. [Rather, I think] if so happens to those who anger [Hashem], how much the more so for those who do His will, in the future, which is the time to receive reward!
Radak: I felt Simchah over their good. They bestow bad in place of good - they feel Simchah over my misfortune!
Malbim: The famine stopped.
Did Hashem put the Simchah in his heart? He chose to be happy over their good fortune!
Radak: If one comes to purify himself, [Shamayim] helps him (Yuma 38b). It is good to rejoice in the good fortune of one's colleagues (and even one's enemies - PF). Hashem helps one who goes in this way!
Malbim: Via giving to them prosperity, Hashem caused David to rejoice. (It seems that also Rashi explains so - PF.)