DataGrid sort when Editing

S

Steve

This may be a common question, however I didn't find any posts on the issue.
When you are editing a row of a datagrid, and then you sort the datagrid, the
edititemindex stays the same, which means that you are now editing a
different item (though the same physical row of the datagrid). How can you
make it so that you are still editing the same data after you sort? As it
is, I am simply clearing the edititemindex. (By the way, this issue also
applies when using the selecteditemindex.)

Your help is appreciated, thank you.
 
E

Elton Wang

Hi Steve,

I suppose you have to implement your own code to solve the
problem. You may use following logic.

When sorting
If edititemindex <> -1 then
Find PK data from edit item
Endif
Sort data source and assign it to datagrid
Find index from PK data
Assign edititemindex = the index
Call datagrid.DataBind


HTH

Elton Wang
(e-mail address removed)
 
S

Scott M.

You'll have to know the index of the row in the dataset. Unfortunately, the
DataSetIndex property doesn't provide this accurately after you have sorted,
so you'll need to find the record manually in the dataset and then get its'
index. You can use the Select method and pass a SQL like search criteria to
help you find the record in the DataSet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top