David was far from perfect, as we all know. But if you read Psalm 51, it might provide some reasons why God loved David's heart:
"For thou desirest not sacrifice; else would I give it: thou delightest not in burnt offering. The sacrifices of God are a broken spirit: a broken and a contrite heart, O God, thou wilt not despise." - Psallm 51:16-17.
Thanks to your post, I have just prayed this Scripture and it is a wonderful feeling.
Indeed Brother, every time I pray it, like right now, it brings tears of joy to these old-man eyes. Thanks be to God that He has broken me so that He can remake me in an image pleasing to Him, fit for living with His family. Maranatha!