C# -- Convert to STRING

finance_teacher
finance_teacher used Ask the Experts™
on
How can I change the below so it does not displays
vSortedColumn as NULL (or something) instead of
"Object reference not set to an instance of an object."
when users don't click on a column header to sort the
gML_ROITEMDataGridView ?

string vSortedColumn = this.gML_ROITEMDataGridView.SortedColumn.ToString();
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
try this,

string vSortedColumn = Convert.ToString(this.gML_ROITEMDataGridView.SortedColumn);
hi,
  It should like :
string vSortedColumn =this.gML_ROITEMDataGridView.SortedColumn == null ? string.Empty : this.gML_ROITEMDataGridView.SortedColumn.ToString();
Mathiyazhagan's arswer is more robust...as when this.gML_ROITEMDataGridView.SortedColumn = null, i thing Convert.ToString will crash.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial