Have you been in the child's life since she was born? If you can provide a healthy environment for her, then you have a chance to get custody of her. Custody judges try to be very sensitive and subjective to these situations. Be sure to be open-minded and sensitive to the grandmother as well, since she just lost her daughter, losing her grandchild could be very difficult as well.
Perhaps try to share custody to reassure the grandmother that you will never take her away. If you appear to be sensitive you are not only doing what is best for the child and helping a mother who has lost her daughter, but the judge will sense that and you will have a better chance.

