954,157 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Data from datatable after datagrid sorting

I have a datatable (sqltable) and a datagrid (dgData)

if the user click the datagrid header the grid changes sort order
but when i try to get

Dim Row As DataRow
Row = sqlTable.Rows(dgData.CurrentCell.RowIndex)

or

Dim Row As DataRow = sqlTable.Rows(e.RowIndex)


the row returned is not the row selected in the datagrid

any ideas how to do this?

Thanks

ptaylor965
Junior Poster
170 posts since Oct 2006
Reputation Points: 16
Solved Threads: 19
 

Try this:

Dim bm As BindingManagerBase = _
dgData.BindingContext(dgData.DataSource, dgData.DataMember)

Dim Row As DataRow = bm.Current.Row

chriswininger
Newbie Poster
5 posts since Dec 2008
Reputation Points: 20
Solved Threads: 0
 

Thanks for the post but since the question was asked on Jun 15th, 2007 I have found an easy answer

Protected dvMyData as New DataView

Then

dvMyData.Table = MyDataTable
dgData.DataSource = dvMyData


Then I can use

dim Row as DataRow = dvMyData(dgDataGrid.CurrentRow.Index)


This has been the best and I have been using it for several months now.


Thanks
Peter

ptaylor965
Junior Poster
170 posts since Oct 2006
Reputation Points: 16
Solved Threads: 19
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You