-1

I have devexpress gridcontrol which I want to fill with data from predefined DataTable. This is my code:

private void SortDataTable()
{
        DataView dv = GetDataTejbl.DefaultView;
        dv.Sort = comboEdit.Text + " " + "DESC";
        DataTable SortedDataTable = dv.ToTable();
        gridControl1.DataSource = SortedDataTable;
}

The error I get:

"Object reference not set to an instance of an object."

  • check to determine if the object is null before calling the method
  • use the "new" keyword to create an object instance
  • get general help for this exception

Any help would be appreciated. Thank you very much

EDIT: The code I've tried

if (GetDataTejbl.Rows.Count > 0)
oljko
  • 52
  • 3
  • 10
  • Duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Bjørn-Roger Kringsjå Oct 02 '15 at 14:49

1 Answers1

1
private void SortDataTable(){

DataView dv = GetDataTejbl.DefaultView.Sort = "["+comboEdit.Text + "] DESC";
DataTable SortedDataTable = dv.ToTable();
if(SortedDataTable!=null){
 gridControl1.DataSource = SortedDataTable;

} }

Padhu
  • 1,590
  • 12
  • 15
  • Thank you very much. It seems that my datatable was empty (I did very poor data "transfer"). Your code helped me to realize that my DataTable was empty. – oljko Oct 02 '15 at 13:28
  • Glad, it helped you. Cheers. – Padhu Oct 02 '15 at 13:42