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

Border formatting problem on scroll

1 Answer 68 Views
GridView
This is a migrated thread and some comments may be shown as answers.
dave
Top achievements
Rank 1
dave asked on 17 May 2008, 04:27 PM
I have a winforms application correctly displaying data from a dataset.

When a user double clicks on a row it opens a document associated with that row - I want the row to then be highlighted (ie create a border around it) so that the user knows they have viewed that item.

the code i'm using for this is:

 dg2.Rows(dg2.SelectedRows(0).ViewInfo.CurrentIndex).VisualElement.BorderColor = Color.Blue
        dg2.Rows(dg2.SelectedRows(0).ViewInfo.CurrentIndex).VisualElement.BorderColor = Color.Blue
        dg2.Rows(dg2.SelectedRows(0).ViewInfo.CurrentIndex).VisualElement.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.OuterInnerBorders
        dg2.Rows(dg2.SelectedRows(0).ViewInfo.CurrentIndex).VisualElement.DrawBorder = True

this works fine - until i use the scroll bars - the highlights stay in the same place visually - but this now highlights the wrong items.

Help please......

1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 19 May 2008, 02:03 PM
Hello dave,

Thank you for this question.

In order to minimize the memory usage and optimize the performance, RadGridView uses virtualization for its row elements. Visual elements are created only for the rows that are visible on the screen. When you scroll they are associated with other rows and their visual state is changed.

Because of all this, you can't assign values directly to a row element. You should process the RowFormatting and CellFormatting events instead. Consider the code snippet below:

Private Sub radGridView1_RowFormatting(ByVal sender As ObjectByVal e As RowFormattingEventArgs) 
    If CBool(e.RowElement.RowInfo.Cells("Visited").Value) Then 
        e.RowElement.BorderColor = Color.Blue 
        e.RowElement.Element.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.OuterInnerBorders 
        e.RowElement.DrawBorder = True 
    Else 
        e.RowElement.DrawBorder = False 
    End If 
End Sub 

I hope this helps. Do not hesitate to write me, if you have other questions.
 

Greetings,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
dave
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or