Loosing checkbox UI status

10 posts, 0 answers
  1. Virendra
    Virendra avatar
    50 posts
    Member since:
    Aug 2012

    Posted 11 May 2009 Link to this post

    Hi,

    when move out of checkbox column, i loose the UI/display status on checkbox.
    It is always displays unchecked box.
    Though it is retaining the values.

    I am not rebinding the source after check/uncheck of checkbox.

    what could be the reason?
    thanks
    virendra
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 11 May 2009 Link to this post

    Hi Virendra,

    I didn't manage to reproduce such issue in our online examples - can you send us a bit more info how to reproduce this?

    Best wishes,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. Hector
    Hector avatar
    92 posts
    Member since:
    May 2009

    Posted 05 Jun 2009 Link to this post

    I had the same problem.  I added a column with a checkbox through the control template.  During runtime, they display fine for every row, but when I check them on and I scroll up or down past the checked items, then scroll back to those items, they are unchecked.
    I am trying to add a check box to each row to select or unselect the rows.  How can I accomplish this? 
    Thanks, Hector

    Here is part of my code:

    Page.xaml

    <ControlTemplate x:Key="AccountTypesTemplate" TargetType="telerikGV:GridViewRow" > 
                        <Border x:Name="rowsContainer" Background="#FF525252" Padding="8,8,8,0" > 
                            <Border Background="{StaticResource Office_BlackRowBackground}" x:Name="selectedRow" 
                                BorderThickness="1" BorderBrush="#FF000000" > 
                                <Grid Width="400">  
                                    <Grid.RowDefinitions> 
                                        <RowDefinition Height="30" /> 
                                        <RowDefinition Height="30" /> 
                                    </Grid.RowDefinitions> 
                                    <Grid.ColumnDefinitions> 
                                        <ColumnDefinition Width="30" /> 
                                        <ColumnDefinition Width="55" /> 
                                        <ColumnDefinition Width="*" /> 
                                        <ColumnDefinition Width="60" /> 
                                        <ColumnDefinition Width="*" /> 
                                    </Grid.ColumnDefinitions> 
     
                                    <CheckBox Grid.Column="0" Grid.Row="0" IsChecked="False" Grid.RowSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" 
                                          Margin="5,5,5,5"/>  
     
                                    <TextBlock Grid.Column="1" Grid.Row="1" Foreground="White" FontWeight="Bold" Margin="0,15,15,0"   
                                    VerticalAlignment="Top" HorizontalAlignment="Left" Text="Phone:" /> 
                                    <TextBlock Grid.Column="3" Grid.Row="1" Foreground="White" FontWeight="Bold" Margin="0,15,15,0"   
                                    VerticalAlignment="Top" HorizontalAlignment="Left" Text="Group:" /> 
                                    <!--Cells--> 
                                    <telerikGV:GridViewCell Grid.Column="1" Grid.Row="0" Foreground="White" FontWeight="Bold" Margin="0,15,15,0"   
                                    VerticalAlignment="Top" HorizontalAlignment="Left" Value="{Binding Description}" Grid.ColumnSpan="4" /> 
                                    <telerikGV:GridViewCell Grid.Column="2" Grid.Row="1" Foreground="White" FontWeight="Bold" Margin="0,15,15,0"   
                                    VerticalAlignment="Top" HorizontalAlignment="Left" Value="{Binding Value}" /> 
                                    <telerikGV:GridViewCell Grid.Column="4" Grid.Row="1" Foreground="White" FontWeight="Bold" Margin="0,15,15,0"   
                                    VerticalAlignment="Top" HorizontalAlignment="Left" Value="{Binding GroupName}" /> 
                                </Grid> 
                            </Border> 
                        </Border> 
                    </ControlTemplate> 
                     <Border  BorderBrush="#FF292E97" BorderThickness="5,5,5,5" CornerRadius="10,10,10,10">  
                                <telerikGridView:RadGridView x:Name="gridMultiSelect_accounts" ScrollMode="RealTime" IsReadOnly="True" ShowGroupPanel="False"   
                                    Width="400" VerticalGridlinesBrush="Transparent" RowStyle="{StaticResource rowStyle}" 
                                    UseAlternateRowStyle="False" AutoGenerateColumns="True" ShowColumnHeaders="False" > 
                                    <telerikGridView:RadGridView.Columns> 
                                        <telerikGridView:GridViewDataColumn UniqueName="ValueID" /> 
                                        <telerikGridView:GridViewDataColumn UniqueName="Value" /> 
                                        <telerikGridView:GridViewDataColumn UniqueName="ChildControl" /> 
                                        <telerikGridView:GridViewDataColumn UniqueName="GroupID" /> 
                                        <telerikGridView:GridViewDataColumn UniqueName="GroupName" /> 
                                        <telerikGridView:GridViewDataColumn UniqueName="Description" /> 
                                        <telerikGridView:GridViewDataColumn UniqueName="DefaultValue" /> 
                                    </telerikGridView:RadGridView.Columns> 
     
                                </telerikGridView:RadGridView> 
                            </Border> 

  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 05 Jun 2009 Link to this post

    Hello Hector,

    You will need to bind (TwoWay) this CheckBox to IsSelected DataRecord property. Grid rows are UI virtualized and every row outside of the viewble area will be destroyed and created again when needed.

    Best wishes,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Hector
    Hector avatar
    92 posts
    Member since:
    May 2009

    Posted 05 Jun 2009 Link to this post

    OK, this makes sence, Vlad.  Can you show me an example of how to bind the checkbox to the DataRecord property?  I am thinking that I don't have my GridView columns set correct for the Checkbox.  I only have the checkbox in the ControlTemplate, but not in the <telerikGridView:RadGridView.Columns>  I am thinking that this is where I need to bind it, right?
  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 09 Jun 2009 Link to this post

    Hello Hector,

    You can find small demo attached.

    Sincerely yours,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  8. Hector
    Hector avatar
    92 posts
    Member since:
    May 2009

    Posted 09 Jun 2009 Link to this post

    Outstanding!   This is an even easier implementation from your previous sample.  My only other question is how do I disable selection on clicking the GridView rows because this will deselect any selection.  I only want to be able to select using the CheckBox.

    Thank you Vlad and all the Telerik team.
  9. Virendra
    Virendra avatar
    50 posts
    Member since:
    Aug 2012

    Posted 09 Jun 2009 Link to this post

    how will you do it,
    if your column in NOT checkbox templed type
    <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox Loaded="CheckBox_Loaded" />
                            </DataTemplate>
    </telerik:GridViewColumn.CellTemplate>

    but are off native Checkbox column like
    <telerik:GridViewDataColumn HeaderText="Delete?" UniqueName="Delete" />
    where column's EditorSettings is CheckboxEditorSettings.

    thanks
    virendra




  10. Hector
    Hector avatar
    92 posts
    Member since:
    May 2009

    Posted 10 Jun 2009 Link to this post

    This is how I did it:

    Page.xaml
    <Grid.Resources> 
    <ControlTemplate x:Key="AccountTypesTemplate" TargetType="telerikGV:GridViewRow" > 
                        <Border x:Name="rowsContainer" Background="#FF525252" Padding="8,8,8,0" > 
                            <Border Background="{StaticResource Office_BlackRowBackground}" x:Name="selectedRow" 
                                BorderThickness="1" BorderBrush="#FF000000" > 
                                <Grid Width="400">  
                                    <Grid.RowDefinitions> 
                                        <RowDefinition Height="30" /> 
                                        <RowDefinition Height="30" /> 
                                    </Grid.RowDefinitions> 
                                    <Grid.ColumnDefinitions> 
                                        <ColumnDefinition Width="30" /> 
                                        <ColumnDefinition Width="55" /> 
                                        <ColumnDefinition Width="*" /> 
                                        <ColumnDefinition Width="60" /> 
                                        <ColumnDefinition Width="*" /> 
                                    </Grid.ColumnDefinitions> 
     
                                    <CheckBox Grid.Column="0" Grid.Row="0"   Grid.RowSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" 
                                        Margin="5,5,5,5" Loaded="CheckBox_Loaded" > 
                                          
                                    </CheckBox> 
     
                                    <TextBlock Grid.Column="1" Grid.Row="1" Foreground="White" FontWeight="Bold" Margin="0,15,15,0"   
                                    VerticalAlignment="Top" HorizontalAlignment="Left" Text="Phone:" /> 
                                    <TextBlock Grid.Column="3" Grid.Row="1" Foreground="White" FontWeight="Bold" Margin="0,15,15,0"   
                                    VerticalAlignment="Top" HorizontalAlignment="Left" Text="Group:" /> 
                                    <!--Cells--> 
                                    <telerikGV:GridViewCell Grid.Column="1" Grid.Row="0" Foreground="White" FontWeight="Bold" Margin="0,15,15,0"   
                                    VerticalAlignment="Top" HorizontalAlignment="Left" Value="{Binding Description}" Grid.ColumnSpan="4" /> 
                                    <telerikGV:GridViewCell Grid.Column="2" Grid.Row="1" Foreground="White" FontWeight="Bold" Margin="0,15,15,0"   
                                    VerticalAlignment="Top" HorizontalAlignment="Left" Value="{Binding Value}" /> 
                                    <telerikGV:GridViewCell Grid.Column="4" Grid.Row="1" Foreground="White" FontWeight="Bold" Margin="0,15,15,0"   
                                    VerticalAlignment="Top" HorizontalAlignment="Left" Value="{Binding GroupName}" /> 
                                </Grid> 
                            </Border> 
                        </Border> 
                    </ControlTemplate> 
     
                    <Style x:Key="rowStyle" TargetType="telerikGV:GridViewRow" > 
                        <Setter Property="Template" Value="{StaticResource AccountTypesTemplate}" /> 
                    </Style> 
                </Grid.Resources> 
     
    <telerikGridView:RadGridView Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2"  x:Name="gridMultiSelect_accounts" ScrollMode="RealTime" IsReadOnly="True" ShowGroupPanel="False"   
                                        Width="400" Height="330" VerticalGridlinesBrush="Transparent" RowStyle="{StaticResource rowStyle}" 
                                        UseAlternateRowStyle="False" AutoGenerateColumns="True" ShowColumnHeaders="False"   
                                        MultipleSelect="True" Margin="5,5,5,5">  
                                    </telerikGridView:RadGridView> 

    Page.xaml.cs
    private void CheckBox_Loaded(object sender, RoutedEventArgs e)  
            {  
                CheckBox checkBox = (CheckBox)sender;  
     
                checkBox.SetBinding(CheckBox.IsCheckedProperty,  
                    new Binding("IsSelected")  
                    {  
                        Mode = BindingMode.TwoWay,  
                        Source = checkBox.ParentOfType<GridViewRow>().Record  
                    });  
            } 

    Thanks Vlad, it works great!
  11. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 18 Jul 2011 Link to this post

    For people using that code, note that the Record class is no more. Just remove Record from the code:
    private void CheckBox_Loaded(object sender, RoutedEventArgs e) 
            
                CheckBox checkBox = (CheckBox)sender; 
      
                checkBox.SetBinding(CheckBox.IsCheckedProperty, 
                    new Binding("IsSelected"
                    
                        Mode = BindingMode.TwoWay, 
                        Source = checkBox.ParentOfType<GridViewRow>()
                    }); 
            }
Back to Top
DevCraft banner