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

Row BackColor does not return after mousehover

6 Answers 125 Views
GridView
This is a migrated thread and some comments may be shown as answers.
gdelatolas
Top achievements
Rank 1
gdelatolas asked on 22 Dec 2009, 11:42 AM
Hi,

I Have a RadGridView (ver 2009.Q3.SP1) and i am formating the rows backcolor using the following code:

 
    Private Sub RGVContacts_RowFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.RowFormattingEventArgs) Handles RGVContacts.RowFormatting  
        If e.RowElement.IsOdd Then  
            e.RowElement.BackColor = Color.Moccasin  
        Else  
            e.RowElement.BackColor = Color.FloralWhite  
        End If  
 
        e.RowElement.DrawFill = True 
    End Sub 

After we have the mouse over a row,  the row is chnaging color and after leaving the row does not return to its original color.
Also, we have the similar problem when selecting one row and then another. The previous selected row does not return to its original color.

Any help will be appreciated.

6 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 23 Dec 2009, 09:21 AM
Hi gdelatolas,

Thank you for your question. You can use AlternatingRowColor property when you want just to show rows with alternating color. Here is a sample:

Me.radGridView1.EnableAlternatingRowColor = True
(DirectCast(Me.radGridView1.GridElement, GridTableElement)).AlternatingRowColor = Color.Moccasin

However, if you want custom effects like a gradient color you have to handle RowFormatting event. The problem is that this event doesn't fire on mouse move. So, you have to handle this event too. Please consider the code snippet below:

Private oldHoveredElement As GridRowElement
 
Sub radGridView1_MouseMove(sender As Object, e As MouseEventArgs)
    Dim cell As GridCellElement = TryCast(Me.radGridView1.ElementTree.GetElementAtPoint(e.Location), GridCellElement)
    If cell <> Nothing Then
        If oldHoveredElement <> cell.RowElement Then
            If oldHoveredElement <> Nothing Then
                oldHoveredElement.UpdateInfo()
            End If
            oldHoveredElement = cell.RowElement
            oldHoveredElement.UpdateInfo()
        End If
    End If
End Sub
 
Sub radGridView1_RowFormatting(sender As Object, e As RowFormattingEventArgs)
    If e.RowElement.RowVisualState = GridRowElement.RowVisualStates.Hovered OrElse e.RowElement.RowVisualState = GridRowElement.RowVisualStates.CurrentHovered OrElse e.RowElement.RowVisualState = GridRowElement.RowVisualStates.Current Then
        e.RowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local)
        e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local)
        e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local)
    Else
        If e.RowElement.IsOdd Then
            e.RowElement.BackColor = Color.Moccasin
        Else
            e.RowElement.BackColor = Color.FloralWhite
        End If
        e.RowElement.DrawFill = True
        e.RowElement.GradientStyle = GradientStyles.Linear
    End If
End Sub

I hope this helps. If you have further questions, do not hesitate to ask.

Sincerely yours,

Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
gdelatolas
Top achievements
Rank 1
answered on 23 Dec 2009, 10:45 AM
Dear Jack,

I am using VB 2008 .Net framework 3.5

After adding your code for MouseMove i have the following error:
    Error 1 Operator '<>' is not defined for types 'Telerik.WinControls.UI.GridRowElement' and 'Telerik.WinControls.UI.GridRowElement'. C:\CPhone4.2\CPhoneClient\FrmMain.vb 123 16 CPhoneClient

at the line:  If oldHoveredElement <> Cell.RowElement Then   
What is missing from my code or my enviroment ?

 Private Sub RGVContacts_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RGVContacts.MouseMove  
        Dim Cell As GridCellElement = TryCast(Me.RGVContacts.ElementTree.GetElementAtPoint(e.Location), GridCellElement)  
 
        If Not IsNothing(Cell) Then  
            If oldHoveredElement <> Cell.RowElement Then  
                If Not IsNothing(oldHoveredElement) Then oldHoveredElement.UpdateInfo()  
                oldHoveredElement = Cell.RowElement  
                oldHoveredElement.UpdateInfo()  
            End If  
        End If  
    End Sub 

Also, we have similar problem when selecting one row and then another.
The previous selected row does not return to its original color.

Thank you
George
0
Jack
Telerik team
answered on 24 Dec 2009, 02:58 PM
Hi gdelatolas,

You have to change the '<>' comparison with Equals. The following code should work:

Private Sub RadGridView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RadGridView1.MouseMove
    Dim cell As GridCellElement = TryCast(Me.RadGridView1.ElementTree.GetElementAtPoint(e.Location), GridCellElement)
    If cell IsNot Nothing Then
        If Not cell.RowElement.Equals(oldHoveredElement) Then
            If oldHoveredElement IsNot Nothing Then
                oldHoveredElement.UpdateInfo()
            End If
            oldHoveredElement = cell.RowElement
            oldHoveredElement.UpdateInfo()
        End If
    End If
End Sub

I can't provide a solution with code when using RadGridView in multi-row selection mode. In this case it will be better to create a custom theme with Visual Style Builder. Nevertheless, we will improve our API in future to support this case. 

I hope this helps. Should you have more questions, please write back.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
gdelatolas
Top achievements
Rank 1
answered on 28 Dec 2009, 07:45 AM
Dear Jack,

Thank you for your support.

The provided code solves the issue concerning mouse over.

Since, there is no solution yet, for selection mode in multi-row grid, we may choose to use the simple coloring ability without gradient as you suggest to your first answer. What property changes the basic row color ? (You are giving us only the alternate color property).

Thank you 
George
0
Accepted
Jack
Telerik team
answered on 28 Dec 2009, 09:27 AM
Hi gdelatolas,

There is no property that controls the default row background color. You have to handle RowFormatting event or modify the theme. However, I found a way to implement gradient alternating row color in multi select mode with code. You should override the default data row element. Please consider the sample below:

Public Class MyDataRow
    Inherits GridDataRowElement
    Public Overloads Overrides Sub UpdateInfo()
        MyBase.UpdateInfo()
        If Me.RowVisualState = RowVisualStates.None Then
            If Me.IsOdd Then
                Me.BackColor = Color.Moccasin
                Me.BackColor2 = Color.Beige
            Else
                Me.BackColor = Color.FloralWhite
                Me.BackColor2 = Color.FloralWhite
            End If
            Me.DrawFill = True
            Me.GradientStyle = GradientStyles.Linear
        Else
            ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local)
            ResetValue(LightVisualElement.BackColor2Property, ValueResetFlags.Local)
            ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local)
            ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local)
        End If
    End Sub
 
    Protected Overloads Overrides Sub OnPropertyChanged(ByVal e As RadPropertyChangedEventArgs)
        MyBase.OnPropertyChanged(e)
        If e.Property.Equals(GridRowElement.RowVisualStateProperty) Then
            UpdateInfo()
        End If
    End Sub
End Class
 
Private Sub RadGridView1_CreateRow(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCreateRowEventArgs) Handles RadGridView1.CreateRow
    If e.RowType.Equals(GetType(GridDataRowElement)) Then
        e.RowType = GetType(MyDataRow)
    End If
End Sub

If you need further assistance, I will be glad to help.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
gdelatolas
Top achievements
Rank 1
answered on 28 Dec 2009, 10:45 AM
Thank you very much.

The provided solution works fine.
Tags
GridView
Asked by
gdelatolas
Top achievements
Rank 1
Answers by
Jack
Telerik team
gdelatolas
Top achievements
Rank 1
Share this question
or