473,378 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Datagrid colum sorting problem - URGENT

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
3 1304
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
2
by: Hrvoje Vrbanc | last post by:
Hello all! I have quite an strange question: I'm using DataGrid to display the results of a query stored in a DataSet. I use data binding with DataBinder.Eval statement (like e.g. <%#...
0
by: Eric | last post by:
Hello, I have a datagrid with sorting enabled. When clickong on the colum names in the header the datagrid is sorted no problem. Unfortunatly, I have a graph that needs to be generated for each...
4
by: bep | last post by:
Hello What is the best way to sort an XmlDocument for display in a DataGrig? I can use Xpath with an XpathExpression, and a XpathNavigator. But this XpathNavigator object is of no use to me, I...
4
by: Manny Chohan | last post by:
hi guys, my code is returning an array and i need to create datagrid so that i can have sorting and implement prev....next function on it to navigate. is there any way this can be done in...
0
by: Dheeraj Verma via DotNetMonster.com | last post by:
Hi all, I have a asp data grid under which i have another datagrid which is my user control and is autogenerated.Now I am not able to implement sorting in my inner datagrid eventhough I have...
5
by: mail | last post by:
Urgent help needed! I moved an application from ASP+ACCESS to ASP+MS SQLSERVER and I have the following problem: If the join on two tables results on duplicate colum names (which appear in...
1
by: ºa¤Ö | last post by:
Dear All Experts I faced a problem, I had developed a UserControl (just a simple display the website logo), and added into a ASPX page. Inside the ASPX, i have a DataGrid control, and it...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.