Sort Arrow glyphs

18 posts, 1 answers
  1. Marc
    Marc avatar
    21 posts
    Member since:
    Dec 2008

    Posted 14 Jan 2009 Link to this post

    Can the sort arrow gliphs be turned on and off in column headers without using the sort feature.  I am unable to use the internal sorting mechanism in radGrid.  I load the grid manually and would like to use the internal sort arrow glyphs to indicate the current sort order.

    I am using VB.net and VS 2008.

    Thank you.
  2. Nick
    Admin
    Nick avatar
    767 posts

    Posted 16 Jan 2009 Link to this post

    Hello Marc,

    Thank you for your question. You can use ViewCellFormatting event for this purpose:

    private void radGridView1_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e) 
            { 
                if (e.CellElement is GridHeaderCellElement)  
                { 
                    (e.CellElement as GridHeaderCellElement).Arrow.ShouldPaint = false
                } 
            } 

    Please take a look at the following help article for details about this event:
    http://www.telerik.com/help/winforms/formatting_cells.html

    Do not hesitate to write me back if you have further questions.

    Regards,
    Nick
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Marc
    Marc avatar
    21 posts
    Member since:
    Dec 2008

    Posted 16 Jan 2009 Link to this post

    Thank you for your response.

    I have tried the following code but get nothing.  As mentioned I am using VB with VS 2008, using your latest grid (Q3 2008) in unbound mode.

    Private Sub radGridSubs_ViewCellFormatting(ByVal sender As ObjectByVal e As CellFormattingEventArgs) Handles radGridSubs.ViewCellFormatting  
     
        If TypeOf e.CellElement Is GridHeaderCellElement Then 
            Dim cell As GridHeaderCellElement = DirectCast(e.CellElement, GridHeaderCellElement)  
     
            cell.Arrow.Direction = Telerik.WinControls.ArrowDirection.Down  
            cell.Arrow.ShouldPaint = True 
        End If 
    End Sub 
     

    As I understand it the above code should place a down arrow in each of the header cells.  I have placed a break point in the code and it is definitely being called, but get no sort arrows.




  4. Nick
    Admin
    Nick avatar
    767 posts

    Posted 19 Jan 2009 Link to this post

    Hello Marc,

    Sorry for the introduced confusion, please comment this line with the Arrow direction. If so, the code from my previous post demonstrates how to turn off the arrow in all cases. You can implement some logic in this event which shows the arrow in some cases and turns it off in others by setting the ShouldPaint property to true or false.

    You may also check about the column and apply your logic only to certain columns using the HeaderText property:

    Private Sub radGridView1_ViewCellFormatting(sender As Object, e As Telerik.WinControls.UI.CellFormattingEventArgs) 
        If e.CellElement.ColumnInfo.HeaderText = "column1" Then 
           
            'check whether arrow should be visible
            'if so set ShouldPaint to true
            'otherwise set ShouldPaint to false
        End If 
    End Sub 

    Please write us back if you have further questions.

    All the best,
    Nick
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Marc
    Marc avatar
    21 posts
    Member since:
    Dec 2008

    Posted 19 Jan 2009 Link to this post

    I am not sure you are actually seeing the issues with this. 

    After playing with this code over the past few days the reason the arrow wasn't being displayed is because you have to set the Visibility property to visible as well.
    cell.Arrow.Visibility = Telerik.WinControls.ElementVisibility.Visible  
    cell.Arrow.Direction = Telerik.WinControls.ArrowDirection.Down  
    cell.Arrow.ShouldPaint = True 
     

    However, I sent you a sample project outlining the bizarre behavior with this feature and the reply was to comment out the arrow direction code, which I don't understand.  I tried it, and it didn't make a difference to the behavior.

    The above code works and the arrow is displayed as expected.  However, if you hover the mouse over the column header the sort arrow disappears.  When the sort arrow disappears the column header text is moved over to the right.  If you click on the column the sort arrow will sometimes return, but then disappear again, moving the column header text over a little bit more.  If you continue the title will eventually move right off the grid.

    I then tried setting the position of the Header text each time I paint the arrow with the following:
    cell.TextAlignment = ContentAlignment.MiddleCenter 

    This works, but doesn't solve the arrow disappearing, or the sliding of the header text when hovering the column header.

    If you need the sample project resent please let me know.

    Any help would be appreciated.
  6. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 21 Jan 2009 Link to this post

    Hi Marc,

    The grid uses the Visibility property to control whether the arrow is visible in its internal logic. So, you should override this logic. As suggested in this thread you could do it when processing the ViewCellFormatting event. The catch is that RadGridView changes the Padding property when the arrow is visible. So we need to override this logic too. Take a look at the code snippet below:

    Private Sub radGridView1_ViewCellFormatting(ByVal sender As ObjectByVal e As CellFormattingEventArgs) 
    Dim cell As GridHeaderCellElement = TryCast(e.CellElement, GridHeaderCellElement) 
    If cell IsNot Nothing Then 
        If ShouldPaintArrow(e.CellElement) Then 
           cell.Arrow.ShouldPaint = True 
           cell.Arrow.Visibility = ElementVisibility.Visible 
           cell.Arrow.Direction = GetArrowDirection(e.CellElement) 
        Dim padding As New Padding() 
           padding.Right = CInt(cell.Arrow.DesiredSize.Width) 2 
           e.CellElement.Padding = padding 
        Else 
           e.CellElement.Padding = New Padding(0) 
           cell.Arrow.ShouldPaint = False 
        End If 
    End If 
    End Sub 
     


    I hope this helps you. Feel free to write us if you need further assistance.

    Sincerely yours,
    Jack
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Marc
    Marc avatar
    21 posts
    Member since:
    Dec 2008

    Posted 21 Jan 2009 Link to this post

    > I  hope this helps you. Feel free to write us if you need further assistance.

    No this did NOT solve the issue and I encourage you try the code, or at least try the sample project you were sent.

    The problem is the arrow disappears when you hover the header cell with the mouse, which in turn slides the column header text over.

    I really hope you can help provide a solution to this, as it makes using this feature unusable.
  8. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 23 Jan 2009 Link to this post

    Hi Marc,

    I didn't noticed that you have sent us your application, so I tested with a simple test app. I checked your app and found that you have set the AllowSort property to false. In this case it is better to create a custom header cells and override the UpdateInfo method. Here is the code:

    Private Sub RadGridView_CreateCell(ByVal sender As ObjectByVal e As Telerik.WinControls.UI.GridViewCreateCellEventArgs) Handles RadGridView1.CreateCell 
        If e.CellType Is GetType(GridHeaderCellElement) Then 
            e.CellElement = New MyHeaderCell(e.Column, e.Row) 
        End If 
    End Sub 
     
    Public Class MyHeaderCell 
        Inherits GridHeaderCellElement 
        Public Sub New(ByVal column As GridViewColumn, ByVal row As GridRowElement) 
            MyBase.New(column, row) 
        End Sub 
     
        Public Overloads Overrides Sub UpdateInfo() 
            MyBase.UpdateInfo() 
     
            Me.Arrow.Visibility = Telerik.WinControls.ElementVisibility.Visible 
            If Me.ColumnIndex = 0 Then 
                Me.Arrow.Direction = Telerik.WinControls.ArrowDirection.Down 
            Else 
                Me.Arrow.Direction = Telerik.WinControls.ArrowDirection.Up 
            End If 
            Me.Padding = New Padding(0, 0, 20, 0) 
        End Sub 
    End Class 
     

    You can remove the code from the ViewCellFormatting method.

    Could you please confirm that everything is OK now. If not, I will be glad helping you further.

    Regards,
    Jack
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  9. Marc
    Marc avatar
    21 posts
    Member since:
    Dec 2008

    Posted 23 Jan 2009 Link to this post

    I tried the code in my project and it appears to be solve the sort arrow issue.  Thank you.

    It did introduce an new issue in that it removes all visual design elements from the header cell. 

    Any way to get this back?
  10. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 26 Jan 2009 Link to this post

    Hello Marc,

    I am glad to hear that the issue with the arrow has been resolved.

    I suppose that you are using a custom theme and the header cells have lost their visual style. There should be no issues when using the default Vista theme. Please add the following code to MyHeaderCell class:

    Protected Overloads Overrides ReadOnly Property ThemeEffectiveType() As Type 
         Get 
            Return GetType(GridHeaderCellElement) 
         End Get 
    End Property 
     
     

    I hope it helps. If not, please open a new support ticket and send me your application. This will allow me to investigatete the case in details.

    Kind regards,
    Jack
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  11. Marc
    Marc avatar
    21 posts
    Member since:
    Dec 2008

    Posted 26 Jan 2009 Link to this post

    I have tried this in the sample project you were sent and it too has bizarre behaviour.  If you turn the arrow off, or change the arrow direction when responding to a cellclick in the header, the change doesn't occur until the mouse hover state changes for each cell.  So essentially you have to hover over each header cell to update the arrow state.

    In any event I would like to use the ViewCellFormating method mentioned earlier in this post.  The only problem with this method was that the arrows and cell text got messed up when hovering the mouse over the header cell. 

    Is there a way to turn OFF the mouse hover action altogether for the header cells?  I really don't need the visual element to change during a mouse hover as much as I need stable sort arrows.

    Hoping you can help.

    PS:  Your controls are still great, just bought the big package the other day.  However, I do feel your radGrid is the
    "red-headed-step-child"
    of the radGrid family.  I little rebelious that is just aching for attention from its father.
  12. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 28 Jan 2009 Link to this post

    Hello Marc,

    Thank you for writing me back. Regarding your questions:

    1. I am not sure how you are updating the cell direction. In my example it depends on the ColumnIndex property and is updated inside the UpdateInfo method. This method is called every time when some cell needs to update its visual state. I modified the code and added a property named ArrowDirection which now controls the arrow direction. It can be changed when processing the CellClick event for example.

    Take a look at the code below:

    Private Sub RadGridView_CreateCell(ByVal sender As ObjectByVal e As Telerik.WinControls.UI.GridViewCreateCellEventArgs) Handles RadGridView1.CreateCell 
        If e.CellType Is GetType(GridHeaderCellElement) Then 
            e.CellElement = New MyHeaderCell(e.Column, e.Row) 
        End If 
    End Sub 
     
    Private Sub RadGridView_CellClick(ByVal sender As ObjectByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles RadGridView1.CellClick 
        Dim cell As MyHeaderCell = TryCast(sender, MyHeaderCell) 
        If Not cell Is Nothing Then 
            cell.ArrowDirection = Telerik.WinControls.ArrowDirection.Up 
        End If 
    End Sub 
    Public Class MyHeaderCell 
        Inherits GridHeaderCellElement 
        Dim Direction As Telerik.WinControls.ArrowDirection 
     
        Public Property ArrowDirection() As Telerik.WinControls.ArrowDirection 
            Get 
                Return Direction 
            End Get 
            Set(ByVal value As Telerik.WinControls.ArrowDirection) 
                If Direction <> value Then 
                    Direction = value 
                    Me.UpdateInfo() 
                End If 
            End Set 
        End Property 
     
        Public Sub New(ByVal column As GridViewColumn, ByVal row As GridRowElement) 
            MyBase.New(column, row) 
            Direction = Telerik.WinControls.ArrowDirection.Down         
        End Sub 
     
        Protected Overloads Overrides ReadOnly Property ThemeEffectiveType() As Type 
            Get 
                Return GetType(GridHeaderCellElement) 
            End Get 
        End Property 
     
        Public Overloads Overrides Sub UpdateInfo() 
            MyBase.UpdateInfo() 
     
            Me.Arrow.Visibility = Telerik.WinControls.ElementVisibility.Visible 
            Me.Arrow.Direction = ArrowDirection 
            Me.Padding = New Padding(0, 0, 20, 0) 
        End Sub 
    End Class 


    If this solution is not suitable for you, please describe your scenario in more detail. I will be glad to help you further.

    2. The internal logic in GridHeaderCellElement hinders solving this issue through processing the ViewCellFormatting. This is possible only with the usage of custom header cell elements.

    3. The mouse hover can't be turned off. Of course, you can override the RadGridView and trap the OnMouseMove method, but this will break its internal logic.

    RadGridView is a major component in our WinForms suite and we take serious all feedback from our customers. Please  let us know if there are any other issues related with RadGridView or the other Telerik WinForms components. We will try to find a solution for you.
     

    Sincerely yours,
    Jack
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  13. Marc
    Marc avatar
    21 posts
    Member since:
    Dec 2008

    Posted 28 Jan 2009 Link to this post

    We are getting very close -- I appreciate your patience.  I have two minor issues left.

    Your code looks like it will work for my situation, but I can't figure out how in the CellClick event do I turn off the arrows in the other header cells. When I turn on the arrow in the current header cell I need to turn off the arrows in all other header cells and I can't figure out how to create a MyHeaderCell object to access the Arrow properties.  

    I would have thought the following code in the CellClick would do it but this doesn't work
     
    Dim cell As MyHeaderCell = TryCast(sender, MyHeaderCell)  
     
    Dim cell2 As MyHeaderCell  
     
    If Not cell Is Nothing Then  
          
        'turn other arrows off  
        cell2 = New MyHeaderCell(RadGridView1.Columns(0), cell.RowElement)  
        cell2.ArrowVisible = Telerik.WinControls.ElementVisibility.Hidden  
          
        'turn on sort arrow  
        cell.ArrowVisible = Telerik.WinControls.ElementVisibility.Visible  
        cell.ArrowDirection = Telerik.WinControls.ArrowDirection.Up  
    End If  
     
     
     

    Also, I am using the VistaTelerik theme and since overriding the ThemeEffectiveType() property in MyHeaderCell class, I have lost all visual element to the header cells except for the last column.  It doesn't matter how many columns I have, only the last column header will have a visual element.  It seems to work with your other themes.  

    Can anything be done to get back the visual element in all header cells?  
  14. Answer
    Jack
    Admin
    Jack avatar
    2333 posts

    Posted 29 Jan 2009 Link to this post

    Hi Marc,

    That is good news.

    Instances of MyHeaderCell class are created when processing the CreateCell event. Later, you can try casting the corresponding cell inside the CellFormatting or CellClick event.

    You cannot change the visual state of the arrow by using the specified code because of the logic inside the MyHeaderCell.UpdateInfo method. This method is called every time when the cell updates its visual state and after processing the CellFormatting event. So it overrides all other changes.

    You should call the Update method of GridElement after changing the arrow direction inside the CellClick event in order to update all other cells. Consider the code snippet below:

    RadGridView1.GridElement.Update(GridUINotifyAction.StateChanged) 

    I also changed a little bit of my previous sample code to better address your requirements:

    Private Sub RadGridView_CreateCell(ByVal sender As ObjectByVal e As Telerik.WinControls.UI.GridViewCreateCellEventArgs) Handles RadGridView1.CreateCell 
            If e.CellType Is GetType(GridHeaderCellElement) Then 
                e.CellElement = New MyHeaderCell(e.Column, e.Row)         
            End If 
        End Sub 
     
        Private Sub RadGridView_CellClick(ByVal sender As ObjectByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles RadGridView1.CellClick 
            Dim cell As MyHeaderCell = TryCast(sender, MyHeaderCell) 
            If Not cell Is Nothing Then 
                cell.ArrowDirection = Telerik.WinControls.ArrowDirection.Down 
                RadGridView1.Tag = cell.ColumnIndex 
                RadGridView1.GridElement.Update(GridUINotifyAction.StateChanged) 
            End If 
        End Sub 
     
        Public Class MyHeaderCell 
            Inherits GridHeaderCellElement 
            Dim Direction As Telerik.WinControls.ArrowDirection 
     
            Public Property ArrowDirection() As Telerik.WinControls.ArrowDirection 
                Get 
                    Return Direction 
                End Get 
                Set(ByVal value As Telerik.WinControls.ArrowDirection) 
                    If Direction <> value Then 
                        Direction = value 
                        Me.UpdateInfo() 
                    End If 
                End Set 
            End Property 
     
     
            Public Sub New(ByVal column As GridViewColumn, ByVal row As GridRowElement) 
                MyBase.New(column, row) 
                Direction = Telerik.WinControls.ArrowDirection.Down 
            End Sub 
     
            Protected Overloads Overrides ReadOnly Property ThemeEffectiveType() As Type 
                Get 
                    Return GetType(GridHeaderCellElement) 
                End Get 
            End Property 
     
            Public Overloads Overrides Sub UpdateInfo() 
                MyBase.UpdateInfo() 
                If CType(Me.GridControl.Tag, Integer) = Me.ColumnIndex Then 
                    Me.Arrow.Visibility = Telerik.WinControls.ElementVisibility.Visible 
                    Me.Arrow.Direction = ArrowDirection 
                Else 
                    Me.Arrow.Visibility = Telerik.WinControls.ElementVisibility.Hidden 
                End If 
                Me.Padding = New Padding(0, 0, 20, 0) 
            End Sub 
        End Class 

    In the code above I am saving the index of the currently sorted column inside the Tag property of RadGridView. Later, you can check this property when processing the UpdateInfo method.

    I have modified the VistaTelerik theme to support overriding header cells. You can find the VistaTelerikModified theme attached here. The changes will be included in our upcoming release.

    If you continue to experience any issues, please send us your application and we will try to solve them. Do not hesitate to contact us if you have any questions.

    All the best,
    Jack
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  15. Marc
    Marc avatar
    21 posts
    Member since:
    Dec 2008

    Posted 30 Jan 2009 Link to this post

    That solved it. Thank you.

    Your support was over the top.. again.

  16. Victor
    Admin
    Victor avatar
    1358 posts

    Posted 02 Feb 2009 Link to this post

    Hi Marc,
    You are more than welcome.
    Please write back if you need further assistance or if you have other questions.

    Regards,
    Victor
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  17. Muhammad
    Muhammad avatar
    3 posts
    Member since:
    Sep 2020

    Posted 08 Dec 2020 in reply to Victor Link to this post

    how can i remove arrow from row header in UI winform radgridview in c# ?

    i am using this code but isn't working 

     if (e.CellElement is GridHeaderCellElement)
                {
                    (e.CellElement as GridHeaderCellElement).Arrow.ShouldPaint = false;
                    (e.CellElement as GridHeaderCellElement).Arrow.BackgroundShape = null;
                    (e.CellElement as GridHeaderCellElement).Arrow.Visibility = ElementVisibility.Collapsed;
                }

     

  18. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4129 posts

    Posted 08 Dec 2020 Link to this post

    Hi, Muhammad,

    In order to hide the sort arrow in the header cells it is necessary to handle the ViewCellFormatting event as it is demonstrated below:

            private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
            {
                GridHeaderCellElement headerCell = e.CellElement as GridHeaderCellElement;
                if (headerCell != null)
                {
                    headerCell.Arrow.Visibility = ElementVisibility.Collapsed;
                }
            }

    I hope this information helps.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Back to Top