gridview randomly changes the rows

4 posts, 0 answers
  1. sergey
    sergey avatar
    2 posts
    Member since:
    Aug 2014

    Posted 07 Aug 2014 Link to this post

    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!




  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 07 Aug 2014 Link to this post

    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.
     
  3. sergey
    sergey avatar
    2 posts
    Member since:
    Aug 2014

    Posted 11 Aug 2014 in reply to Dimitrina Link to this post

    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












  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 11 Aug 2014 Link to this post

    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.
     
Back to Top