DataGrid - Sorting Problem

M

Mubashar Ahmad

Dear Frnds

I m using DataGrid Control in my project.

On the mouse Up event i get the information from DataGrid row using Currencty Manager. code is below

private void dgPassengers_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)

{

string tHistoryId;

if (dsInquiry.Tables["QueryHistory"].DefaultView.Count > 0)

{

HistoryId = ((DataRowView)cmQuery.Current).Row["HistoryID"].ToString();

this.HistoryId = tHistoryId;

this.DoAction(InquiryActions.EditQuery);

}

}

it is working fine. but when i click on the Column header it sorts the Grid and it should also give the information of the row where the Record pointer is located. but it gives wrong information.

or we can say it doesn't move the record pointer to the row it was pointing before sorting.

please give suggestion

thanks and regards

Mubashar Ahmad
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hello,

The data grid won't retain its current position after being re-sorted. You
should restore the position manually, possibly by remembering a unique row
primary key and searching the row's position in the updated data view
accessible through the CurrencyManager's List property by the stored primary
key.
 
M

Mubashar Ahmad

Thanks Dmitriy Lapshin

your suggestion is quit reasonable now please let me know how can i capture
sort event. i dont think that datagrid provides such event. and tell me also
is it a event of dataGrid or
DataGridColumn.

thanks once again and Regards

Mubashar Ahmad
 
D

Dmitriy Lapshin [C# / .NET MVP]

There's no dedicated event. You can capture the grid's MouseDown event and
determine whether the user has clicked on a column header by using the
grid's HitTest method.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Mubashar Ahmad said:
Thanks Dmitriy Lapshin

your suggestion is quit reasonable now please let me know how can i capture
sort event. i dont think that datagrid provides such event. and tell me also
is it a event of dataGrid or
DataGridColumn.

thanks once again and Regards

Mubashar Ahmad



Dmitriy Lapshin said:
Hello,

The data grid won't retain its current position after being re-sorted. You
should restore the position manually, possibly by remembering a unique row
primary key and searching the row's position in the updated data view
accessible through the CurrencyManager's List property by the stored primary
key.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
 

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

Top