Mauricio
Thu Nov 13 12:40:54 CST 2003
Hi Ying-Shen Yu [MSFT],
This solution didn't resolve, because I have other tables
related and this solution treat only one table.
My application has a main form with 4 datagrids. Each one
is bound with the same dataset, but different related
tables. I select a row of anyone datagrids and open a
second form to edit the selec row. This second form has
some controls (textboxes and comboboxes) bound with the
same main form's dataset. In the second form load event
it's initiated its BindContext().Position with the same
values of the main form. If I don't sort the main fom's
datagrids, it's ok, otherwise the second form shows a
different row.
I don't know what to do. For the time being I disable the
datagrid sort property, but I hope that you can help me.
Best Regards,
Mauricio
>-----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!
>
>
>.
>