This is a migrated thread and some comments may be shown as answers.

Select first row after sort

11 Answers 902 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Charles Guthrie
Top achievements
Rank 1
Charles Guthrie asked on 30 Jun 2009, 01:58 PM
I'm loading data into a GridView and then programatically applying a multi-column sort.  I'd like to place the user on the first row of the sorted results when the grid opens.  The code:

this.gridChanges.Rows[0].IsSelected = true;

Seems to place the user at the first row of the unsorted data.  How you I place them at the first row of the sorted data?

11 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 01 Jul 2009, 09:20 AM
Hi Charles Guthrie,

You should use the IsCurrent property instead. The IsSelected property indicates that the specified row is selected. This is useful when RadGridView is in multi-row select mode. Should you have any other questions, I will be glad to help.

Regards,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Brian Peters
Top achievements
Rank 1
answered on 13 Apr 2011, 09:39 PM
Hi,
I am using RadControls for WinForms Q1 2011 with the following code and the first row in the grid is not the one selected, the 19th row is (after the sorting).
How do I get the first row in the grid to be current and selected after the sorting logic is applied.

With grdPermissionItems2
 
    .DataSource = Nothing
    .ClearSelection()
    .DataSource = dsData.Tables(0)
    .Visible = True
 
    .AllowAddNewRow = False
    .AllowDeleteRow = False
    .AllowEditRow = False
    .EnableCustomGrouping = False
    .EnableGrouping = False
    .EnableSorting = True
 
    .Columns(1).Sort(Telerik.WinControls.UI.RadSortOrder.Ascending, False)
 
    .Rows(0).IsCurrent = True
 
End With

Thanks in advance.
0
Jack
Telerik team
answered on 18 Apr 2011, 03:16 PM
Hi Brian Peters,

The Rows collection contains all rows in the same order they are ordered in the underlying data source. You should use the ChildRows collection to access the sorted rows. Here is a sample:
.ChildRows(0).IsCurrent = True

I hope this helps.
 
Kind regards,
Jack
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Alwin
Top achievements
Rank 1
answered on 16 Dec 2013, 11:49 AM

Hi,

i thought

RadGridView1.GridNavigator.SelectFirstRow();

should do everything needed to select the first visible row, but it seems that first row of Rows is selected.


Is there any other BuildIn method to select the first ChildRow?



Best regards



Alwin

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Dec 2013, 10:28 AM
Hello Alwin,

Thank you for contacting Telerik Support.

If I understand your requirement correctly, you are trying to select the first row after sorting is performed. For this purpose, you may use the SortChanged event and perform selection via the GridNavigator as you mentioned:
private void Form1_Load(object sender, EventArgs e)
{
    this.employeesTableAdapter.Fill(this.nwindDataSet.Employees);
 
    radGridView1.SortChanged += radGridView1_SortChanged;
}
 
private void radGridView1_SortChanged(object sender, GridViewCollectionChangedEventArgs e)
{
   radGridView1.GridNavigator.SelectFirstRow();
}

If it is not the exact requirement, please specify more details about the expected behavior.

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Alwin
Top achievements
Rank 1
answered on 19 Dec 2013, 10:50 AM

Hello Desislava,


after reading this thread i changed to ChildRows[0], because SelectFirstRow didn't worked as expected.

For testing your sample i switched back to SelectFirstRow, and it also works as expected...



So everythings works fine... crazy...



Best regards

Alwin

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Dec 2013, 12:29 PM
Hello Alwin,

Thank you for getting back to me.

I am glad that the issue you were facing is now resolved. If you encounter again unexpected behavior of GridNavigator.SelectFirstRow(), we would really appreciate your sample project, successfully reproducing the issue. Thus, we would be able to investigate the case.

Please do not hesitate to contact us if you have any additional questions.

Regards,
Desislava
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Jeffrey
Top achievements
Rank 1
answered on 13 May 2014, 01:03 AM
Hi,
This worked for me in a way but the performance slowed down a lot when compared to when I didn't use this to select first row. Seems like it takes 3-4x longer now.

Try
           If RDLDataType.Text = "Drug Screen Group" Then
               If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
                   'Get clickonce deployment version.
                   Dim exporter As New ExportToPDF(Me.RadGridView1)
 
                   'PDF formatting.
                   Me.RadGridView1.Columns("IntakeDate").ExcelExportType = DisplayFormatType.ShortDate
                   exporter.FileExtension = "pdf"
                   exporter.PageTitle = "Drug Screen Group"
                   exporter.FitToPageWidth = True
                   exporter.PdfExportSettings.Author = GeneralCode.FirstName & " " & GeneralCode.SurName
                   exporter.PdfExportSettings.Creator = My.Application.Info.Version.ToString
                   exporter.PdfExportSettings.Title = "Drug Screen Report"
                   exporter.ExportVisualSettings = True
                   AddHandler exporter.HTMLCellFormatting, AddressOf htmlExporter_HTMLCellFormatting
                   exporter.RunExport(Me.SaveFileDialog1.FileName)
 
                   'Load agency referrals here.
                   Dim myCommand As New MySqlCommand
                   Dim myAdapter As New MySqlDataAdapter
                   Dim myData As New DataTable
                   MySQL.mysqlOpen()
                   myCommand.Connection = MySQL.conn
 
                   'Update program log.
                   myCommand.CommandText = "INSERT INTO manalive.programlog (userID, eventID, eventDescription, eventDetail) VALUES ('" & GeneralCode.ID & "', 'M12', 'Drug Screen Group Export PDF', '" & GeneralCode.UserID & "')"
                   myCommand.ExecuteNonQuery()
                   MySQL.mysqlClose()
 
                   'Send desktop alert for save.
                   frmParent.DesktopAlert = "Datum"
                   frmParent.DesktopContent = RDLDataType.Text & " has been exported as PDF file."
 
               End If
           End If
       Catch ex As Exception
           MsgBox("Error exporting to Excel.", MsgBoxStyle.Information)
       End Try
0
Jeffrey
Top achievements
Rank 1
answered on 13 May 2014, 01:06 AM
Forgot to include this in previous post as this is the sub I'm using along with code I just posted:

Private Sub htmlExporter_HTMLCellFormatting(sender As Object, e As HTMLCellFormattingEventArgs)
      Try
          'Format datetime column in PDF.
          If e.GridColumnIndex = 3 AndAlso Not [String].IsNullOrEmpty(e.InnerCellValue.ToString()) Then
              e.HTMLCellElement.Value = DirectCast(e.InnerCellValue, DateTime).ToString("MM/dd.yyyy")
          End If
      Catch ex As Exception
          MsgBox("Problem converting value in Intake Date column.", MsgBoxStyle.Information)
      End Try
  End Sub
0
Jeffrey
Top achievements
Rank 1
answered on 13 May 2014, 01:09 AM
Sorry, long day this is the correct sub:

Private Sub radGridView1_SortChanged(sender As Object, e As GridViewCollectionChangedEventArgs)
       radGridView1.GridNavigator.SelectFirstRow()
   End Sub
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 May 2014, 02:47 PM
Hello Jeffrey,

Thank you for writing.

I was unable to reproduce the performance issue you are facing with the latest version (Q1 2014 SP1). I have attached my sample project. Feel free to modify it on a way to reproduce the experienced issue and get back to me, providing the sample code so I can investigate the precise case. Thank you in advance.

P.S. It is possible to call EnsureVisible method for the first row in the sorted data, which may speed up the performance in some cases.
Private Sub RadGridView1_SortChanged(sender As Object, e As GridViewCollectionChangedEventArgs) _
Handles RadGridView1.SortChanged
    RadGridView1.ChildRows(0).EnsureVisible()
    RadGridView1.GridNavigator.SelectFirstRow()
End Sub

You can set the threshold, which defines what sorting algorithm will be used. When the items count is greater than the threshold, BinaryTree will be used to perform the sorting operations. You can use the following code:
Dim dataView As RadDataView(Of GridViewRowInfo) = TryCast(Me.RadGridView1.GridViewElement.Template.ListSource.CollectionView, RadDataView(Of GridViewRowInfo))
Dim indexerField As FieldInfo = GetType(RadDataView(Of GridViewRowInfo)).GetField("indexer", BindingFlags.NonPublic Or BindingFlags.Instance)
Dim indexer As HybridIndex(Of GridViewRowInfo) = TryCast(indexerField.GetValue(dataView), HybridIndex(Of GridViewRowInfo))
indexer.Threshold = 500

I am looking forward to your reply.

Regards,
Desislava
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Charles Guthrie
Top achievements
Rank 1
Answers by
Jack
Telerik team
Brian Peters
Top achievements
Rank 1
Alwin
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Jeffrey
Top achievements
Rank 1
Share this question
or