Even though God had told him that the child would die, David still thought there was a chance God would be gracious and allow the child to live. David had a lot of faith in the compassion and grace of God. However on this occasion God did not relent.
David accepted God's decision without a word of complaint. David understood God was Sovereign and worthy of worship, even when God disappointed him.
These two things: David's strong belief in the compassion and grace of God and David's understanding of the Sovereignty of God, help us to understand why God called him "a man after my own heart" (Act 13:22).