Two incidents in David's life in which he inquired of the Lord:
After Saul's and Jonathan's deaths, David asked what he should do next (2 Samuel 2:1-2). As David comes to power, he did so in humility, showing kindness even to those who had honored Saul by burying him (2 Samuel 2:4-7).
David asked God what to do on two occasions when the Philistines came up to attack him (2 Samuel 5:17-25). Both times, the threat came, David inquired of the Lord, God answered, and David obeyed. See Paul's summary of King David in Acts 13:22.
A summary of David's actions:
"Inquiring of the Lord" is an attitude of heart, not simply an action in a moment of crisis.
"Inquiring of the Lord" is a habit for David (1 Samuel 22:3-5; 30:7-8).
What can we learn from David's humble heart?
Avoid the thirst for power or revenge (see Philippians 2:5-7).
Cultivate a heart that is attentive to God in everyday life. How do we inquire of the Lord? (1) Through daily habits of devotional time with God. (2) By consciously involving your loving Father in your ongoing internal conversation throughout the day. (3) By involving God in our day-to-day conversations with each other.