By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,558 Members | 1,673 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,558 IT Pros & Developers. It's quick & easy.

Datagrid colum sorting problem - URGENT

P: n/a
I found that rows in datagrid can be sorted by clicking on the column
header. However, this doesn't refresh the .currentindex
DataGrid1.CurrentCell.RowNumber

I need either to disable colum sorting programmatcially or somehow refresh
the DataGrid1.CurrentCell.RowNumber index so that it will reflect the
correct rownumber.

Any help is greatly appreciated!

Bill


Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

Use the datatables default view to return right datarow. Quick
example.
Dim ds As New DataSet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim strConn As String

Dim strSQL As String

Dim da As OleDbDataAdapter

Dim conn As OleDbConnection

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn &= "Data Source = Northwind.mdb;"

conn = New OleDbConnection(strConn)

da = New OleDbDataAdapter("Select * From Categories", conn)

da.Fill(ds, "Categories")

DataGrid1.DataSource = ds.Tables("Categories")

End Sub

Private Sub Form1_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.DoubleClick

Dim cm As CurrencyManager = CType(Me.BindingContext(DataGrid1.DataSource),
CurrencyManager)

Dim drv As DataRowView

drv = ds.Tables("Categories").DefaultView.Item(cm.Positi on)

MessageBox.Show(drv.Item("CategoryName").ToString)

End Sub
Disable sort on grid

Set the datagrids or tablestyle if you added one Allowsorting to false

http://msdn.microsoft.com/library/de...rtingtopic.asp
Ken

---------------------------
"Bill Nguyen" <bi*****************@jaco.com> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
I found that rows in datagrid can be sorted by clicking on the column
header. However, this doesn't refresh the .currentindex
DataGrid1.CurrentCell.RowNumber

I need either to disable colum sorting programmatcially or somehow refresh
the DataGrid1.CurrentCell.RowNumber index so that it will reflect the
correct rownumber.

Any help is greatly appreciated!

Bill

Nov 21 '05 #2

P: n/a
Dear Ken;

Thanks for the tip.
I was able to set allowSortingg to False. However, still want to be able to
set allowsorting to True and get the correct rowid to display the record
detail on the right portion of the form.
The problem I seemed to have is that when you clicck on the column header to
sort ASC or DESC, the orgirinal rowid won't change to reflect the new sort
order. Will the CurrencyManager in your sample resolve this issue?
Thanks again

Bill

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OP**************@TK2MSFTNGP15.phx.gbl...
Hi,

Use the datatables default view to return right datarow. Quick
example.
Dim ds As New DataSet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim strConn As String

Dim strSQL As String

Dim da As OleDbDataAdapter

Dim conn As OleDbConnection

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn &= "Data Source = Northwind.mdb;"

conn = New OleDbConnection(strConn)

da = New OleDbDataAdapter("Select * From Categories", conn)

da.Fill(ds, "Categories")

DataGrid1.DataSource = ds.Tables("Categories")

End Sub

Private Sub Form1_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.DoubleClick

Dim cm As CurrencyManager = CType(Me.BindingContext(DataGrid1.DataSource),
CurrencyManager)

Dim drv As DataRowView

drv = ds.Tables("Categories").DefaultView.Item(cm.Positi on)

MessageBox.Show(drv.Item("CategoryName").ToString)

End Sub
Disable sort on grid

Set the datagrids or tablestyle if you added one Allowsorting to false

http://msdn.microsoft.com/library/de...rtingtopic.asp
Ken

---------------------------
"Bill Nguyen" <bi*****************@jaco.com> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
I found that rows in datagrid can be sorted by clicking on the column
header. However, this doesn't refresh the .currentindex
DataGrid1.CurrentCell.RowNumber

I need either to disable colum sorting programmatcially or somehow refresh
the DataGrid1.CurrentCell.RowNumber index so that it will reflect the
correct rownumber.

Any help is greatly appreciated!

Bill


Nov 21 '05 #3

P: n/a
Bill,

I don't use the

DataGrid1.CurrentCell.RowNumber

However that

CType(Me.BindingContext(DataGrid1.DataSource),
CurrencyManager).Position

That you see in the sample from Ken.

I hope this helps,

Cor
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.