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

gridview randomly changes the rows

3 Answers 56 Views
GridView
This is a migrated thread and some comments may be shown as answers.
sergey
Top achievements
Rank 1
sergey asked on 07 Aug 2014, 12:19 PM
hi !
im having trouble with GridView.
my grid view contains about 100 columns and 100 rows and the first column has check box in it.
the check box can get checked or unchecked through  code and through UI,
if the check box is checked i change the border color and border thickness of the entire row.
if i scroll down to the end of the grid, check some of the check boxes and then scroll back up,
in addition to the checked check boxes, ill see different rows getting checked and their border color and thickness change as well
the rows that get checked are in the same pattern as the original checked rows, for example;

if i check the rows the following way-
|___|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|_V_|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|_V_|___|___|___|___|
|_V_|___|___|___|___|
|___|___|___|___|___|
|_V_|___|___|___|___|


when i will scroll up ill see the same pattern over and over on different rows:

|___|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|_V_|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|_V_|___|___|___|___|
|_V_|___|___|___|___|
|___|___|___|___|___|
|_V_|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|_V_|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|_V_|___|___|___|___|
|_V_|___|___|___|___|
|___|___|___|___|___|
|_V_|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|_V_|___|___|___|___|
|___|___|___|___|___|
|___|___|___|___|___|
|_V_|___|___|___|___|
|_V_|___|___|___|___|
|___|___|___|___|___|
|_V_|___|___|___|___|



each row has a different data context but when the CheckedChanged event invokes for the check boxes in the random rows, their data context is null.
if i check them manually they will have the right datacontext tho.

please help!




3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 07 Aug 2014, 02:51 PM
Hi,

I tested defining my column with CheckBox values like so: 
<telerik:GridViewColumn IsReadOnly="True">
   <telerik:GridViewColumn.CellTemplate>
       <DataTemplate>
           <CheckBox IsChecked="{Binding IsSelected}"/>
       </DataTemplate>
   </telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>

The IsSelected property is a property of the bound object. I checked some items and then I scrolled up and down. As a result all the values remains correct.

Usually this behavior is a result of working with the visual elements, i.e. GridViewCell, GridViewRow etc.
Generally working with the visual elements would not be a recommended approach. Since RadGridView supports UI Virtualization, its rows/cells are reused, which means that on scrolling each cell is loaded and unloaded. You can check our online documentation on UI Virtualization for a further reference.

May I ask you to share more information on the exact implementation you have? 

Regards,
Didie
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.
 
0
sergey
Top achievements
Rank 1
answered on 11 Aug 2014, 02:57 PM
Hey Didie,

Thank you for your reply, I actually managed to find the solution.
Instead of working with the GridViewCell and change the IsChecked property of the checkbox, I'm changing the the row's datacontext
and then call GridView.Items.Refresh method.
Now it works perfectly.

Thank you again and best wishes,
Sergey
A nobody programmer












0
Dimitrina
Telerik team
answered on 11 Aug 2014, 03:34 PM
Hi,

I am glad to hear you managed to find a solution, however, I am not sure what do you mean by "changing the row's datacontext".
I can suggest you working with the bound items directly (this is actually the DataContext of the row).

It is also accessible with the code bellow:
Club item = e.Row.Item as Club;

Regards,
Didie
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
sergey
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
sergey
Top achievements
Rank 1
Share this question
or