-----Mensagem original-----
Hi Mauricio,
I found a similiar issue and another Support Engineer from Microsoft has
given an solution to it.
I past the solution here, please be free to reply to this thread if you
feel it is not helpful to the problem.
For full thread, you may find it at this link:
http://groups.google.com/groups?hl=zh-CN&lr=&ie=UTF- 8&oe=UTF-8&threadm=8%23e
GfszPCHA.1900%40cpmsftngxa07&rnum=1&prev=/groups%3Fhl%
3Dzh-CN%26lr%3D%26ie%3
DUTF-8%26oe%3DUTF-8%26q%3DMSFT%2Bsort%2Bdatagrid
<cite>
Alastair,
If your datagrid is bound to a DataTable then it will be bound to the
Default DataView. Clicking on a column header will change the sort order
for that dataview. Reading a row index from that datagrid will get you the
index of the row as it exist in the sorted dataview, hence, it will not
match the index of the same row in the unsorted atatable.
SO if you create an explicit dataview object from the datatable and then
bind the datagrid to it, you should have no problem. Here is sample code
that binds dataview to a datagrid:
da.Fill(ds, "customers")
dv = ds.Tables("customers").DefaultView
dv.Sort = "CustomerID"
DataGrid1.DataSource = dv
cm = CType(Me.BindingContext(dv), CurrencyManager)
SortColumnName = dv.Sort
now in the mousedown event, need to know the column name if the use clicks
on a column header then you do:
Dim myGrid As DataGrid = CType(sender, DataGrid)
Dim hti As DataGrid.HitTestInfo
hti = myGrid.HitTest(e.X, e.Y)
Select Case hti.Type
Case System.Windows.Forms.DataGrid.HitTestType.ColumnHeader
SortColumnName = dv.Table.Columns (hti.Column).ColumnName
..
and then in the search button, set the sort order of the dataview then
search the sorted dataview:
Dim i As Integer
dv.Sort = SortColumnName
i = dv.Find(TextBox1.Text)
DataGrid1.Select(i)
cm.Position = i
I hope this helps!
Thanks,
Hussein Abuthuraya
Microsoft Developer Support
</cite>
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!
.