DataView.Find() after sorting datagrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm getting an "invalid cast" error message when trying do use Dataview.Find() method to get the row I need to update in my datagrid. The problem just occurs after I sort the datagrid by a non default order.

// Update grid code
string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
int rowIndex = dv.Find(key);

//Sort Grid code
dv.Sort = e.SortExpression;
DataGrid1.DataBind();
 
Hi Paulo,

That's because Find searches by sort order columns.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Paulo said:
I'm getting an "invalid cast" error message when trying do use
Dataview.Find() method to get the row I need to update in my datagrid. The
problem just occurs after I sort the datagrid by a non default order.
// Update grid code
string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
int rowIndex = dv.Find(key);

//Sort Grid code
dv.Sort = e.SortExpression;
DataGrid1.DataBind();
 
Hi Miha,

What can I do then? How can I solve the problem?

Many thanks, Paulo

Miha Markic said:
Hi Paulo,

That's because Find searches by sort order columns.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Paulo said:
I'm getting an "invalid cast" error message when trying do use
Dataview.Find() method to get the row I need to update in my datagrid. The
problem just occurs after I sort the datagrid by a non default order.
// Update grid code
string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
int rowIndex = dv.Find(key);

//Sort Grid code
dv.Sort = e.SortExpression;
DataGrid1.DataBind();
 
Hi Paulo,

You might create another view that is sorted by your key column.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Paulo said:
Hi Miha,

What can I do then? How can I solve the problem?

Many thanks, Paulo

Miha Markic said:
Hi Paulo,

That's because Find searches by sort order columns.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Paulo said:
I'm getting an "invalid cast" error message when trying do use
Dataview.Find() method to get the row I need to update in my datagrid. The
problem just occurs after I sort the datagrid by a non default order.
// Update grid code
string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
int rowIndex = dv.Find(key);

//Sort Grid code
dv.Sort = e.SortExpression;
DataGrid1.DataBind();
 
Back
Top