PC Review


Reply
Thread Tools Rate Thread

Datagrid - keep selected row after user re-sorts

 
 
Sam
Guest
Posts: n/a
 
      25th Aug 2003
Ok.

I have a dataset with a datatable called "Books".

Books contains ISBN, TITLE, and AUTHOR

In my datagrid, I only show TITLE and AUTHOR

I also have a dataview set up with it:

cm = CType(Me, Control).BindingContext(grdBooks.DataSource, _
grdBooks.DataMember)
m_dvwBookView = CType(cm.List, DataView)

I want to be able to keep the row selected, even after the user
re-sorts the datagrid by clicking on a column heading. I can store
the selected ISBN number when the user selects a new row, but I can't
figure out how to find the row with that ISBN #, after the user has
sorted by say TITLE. I can get the event when a user sorts by title
or author with the DataViews ListChanged event:

Private Sub m_dvwBookView_ListChanged(ByVal sender As Object, _
ByVal e As System.ComponentModel.ListChangedEventArgs) _
Handles m_dvwBookView.ListChanged

If (e.ListChangedType = ComponentModel.ListChangedType.Reset) Then
grdBooks.Select(OldRowSelected)
End If
End Sub

I can't figure out how to get the new row index of the previously
selected row. Any ideas?


Thanks...
 
Reply With Quote
 
 
 
 
Eric Cadwell
Guest
Posts: n/a
 
      25th Aug 2003
I prefer to use DataTable.Rows.Find. (You can get the Table via the
DataView.Table property)
((DataTable)Grid.DataSource).Rows.Find(PrimaryKey);

Or you can loop the rows and check the value.

Use DataGrid.Select(int row) when you get the index of the row.

HTH,
Eric Cadwell
http://www.origincontrols.com



"Sam" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Ok.
>
> I have a dataset with a datatable called "Books".
>
> Books contains ISBN, TITLE, and AUTHOR
>
> In my datagrid, I only show TITLE and AUTHOR
>
> I also have a dataview set up with it:
>
> cm = CType(Me, Control).BindingContext(grdBooks.DataSource, _
> grdBooks.DataMember)
> m_dvwBookView = CType(cm.List, DataView)
>
> I want to be able to keep the row selected, even after the user
> re-sorts the datagrid by clicking on a column heading. I can store
> the selected ISBN number when the user selects a new row, but I can't
> figure out how to find the row with that ISBN #, after the user has
> sorted by say TITLE. I can get the event when a user sorts by title
> or author with the DataViews ListChanged event:
>
> Private Sub m_dvwBookView_ListChanged(ByVal sender As Object, _
> ByVal e As System.ComponentModel.ListChangedEventArgs) _
> Handles m_dvwBookView.ListChanged
>
> If (e.ListChangedType = ComponentModel.ListChangedType.Reset) Then
> grdBooks.Select(OldRowSelected)
> End If
> End Sub
>
> I can't figure out how to get the new row index of the previously
> selected row. Any ideas?
>
>
> Thanks...



 
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
Syncronizing rows after the dataGrid sorts Bob Calvanese Microsoft C# .NET 0 20th Feb 2005 03:15 PM
Rows 12 thru 24 are selected in a datagrid. How do I tell when the user selects rows 45 thru 70 ??? BBFrost Microsoft C# .NET 6 26th Oct 2004 04:37 AM
DataGrid sorts all but first row jib Microsoft ADO .NET 2 7th Dec 2003 05:42 PM
Datagrid: get value from the row selected by user Northern Microsoft ASP .NET 1 22nd Jul 2003 09:59 PM
Need Help Determining DataGrid Column Selected for Sort using IBindingList - Datagrid.zip (0/1) David Elliott Microsoft Dot NET Framework Forms 1 18th Jul 2003 02:22 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:03 AM.