PC Review


Reply
Thread Tools Rate Thread

Datagrid colum sorting problem - URGENT

 
 
Bill Nguyen
Guest
Posts: n/a
 
      24th Mar 2005
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




 
Reply With Quote
 
 
 
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      24th Mar 2005
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.Position)

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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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





 
Reply With Quote
 
Bill Nguyen
Guest
Posts: n/a
 
      25th Mar 2005
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.Position)
>
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> 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
>
>
>
>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      25th Mar 2005
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


 
Reply With Quote
 
Bill Nguyen
Guest
Posts: n/a
 
      28th Mar 2005
Dear Ken;
I'm sorry for being a slow learner. I have the following functions/subs but
they seemed to be not working when I double-clicked on the Datagrid:

Private Sub DataGrid1_Navigate(ByVal sender As System.Object, ByVal ne As
System.Windows.Forms.NavigateEventArgs) Handles DataGrid1.Navigate

'txtBolID.Text = "hello!"

'

Dim s As String = "Selected rows:"

Dim o As Object

For Each o In GetSelectedRows(DataGrid1)

s += " " + o.ToString()

' MsgBox(s)

Next o







End Sub



Public Function GetSelectedRows(ByVal dg As DataGrid) As
System.Collections.ArrayList

'Dim alMvmt, alProd As String

Dim al As New ArrayList

Dim cm As CurrencyManager = Me.BindingContext(dg.DataSource, dg.DataMember)

Dim dv As DataView = CType(cm.List, DataView)

dv.AllowNew = False

'

Dim i As Integer

For i = 0 To dv.Count - 1

If dg.IsSelected(i) Then

al.Add(i)

alCustID = dv.Table.Rows(i).Item("custid")

alCustName = dv.Table.Rows(i).Item("custMPName")

' MsgBox(i & alCustID & " - " & alCustName)

End If

Next

Return al

'Return i



"Ken Tucker [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.Position)
>
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> 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
>
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent... datagrid problem Brock Microsoft ASP .NET 2 2nd Jul 2008 06:52 PM
DataGrid paging problem with asp.net urgent help =?Utf-8?B?YW1qYWQ=?= Microsoft ASP .NET 0 28th Jul 2006 12:24 PM
<URGENT>Sorting in nested datagrid Dheeraj Verma via DotNetMonster.com Microsoft ASP .NET 0 31st Jan 2005 08:29 AM
Pleas Urgent help in DataGrid problem gops Microsoft ASP .NET 0 29th Apr 2004 01:42 PM
Sorting a datagrid URGENT!!! Chris Calhoun Microsoft C# .NET 4 10th Dec 2003 08:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:57 AM.