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

Recommended Answers

Try this:

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

Dim Row As DataRow = bm.Current.Row

Jump to Post

All 2 Replies

Try this:

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

Dim Row As DataRow = bm.Current.Row

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.