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

DataGrid)Collapsed CheckBox in CellTemplate gets visible on scrolling

3 Answers 171 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
Dhanraj
Top achievements
Rank 1
Dhanraj asked on 13 Jun 2020, 10:49 AM

I have a checkbox in the cell template that has the visibility attribute.
On Loading, it works but after scrolling, It is showing

Please take look into below code

<telerikGrid:DataGridTemplateColumn Width="35" SizeMode="Fixed" >
                            <telerikGrid:DataGridTemplateColumn.Header>
                                <CheckBox />
                            </telerikGrid:DataGridTemplateColumn.Header>
                            <telerikGrid:DataGridTemplateColumn.CellContentTemplate>
                                <DataTemplate>
                                    <CheckBox  Visibility="{Binding IsSerialSelectedCheckboxVisible}" />
                                </DataTemplate>
                            </telerikGrid:DataGridTemplateColumn.CellContentTemplate>
                        </telerikGrid:DataGridTemplateColumn>

3 Answers, 1 is accepted

Sort by
0
Didi
Telerik team
answered on 15 Jun 2020, 03:20 PM

Hi Dhanraj,

Thank you for the provided code.

In order to keep the checkbox visibility state you will need to set two way binding mode and implement INotifyPropertyChanged interface, for example:

the DataGrid definition:

 

<telerikGrid:RadDataGrid x:Name="grid" AutoGenerateColumns="False" 
                         VerticalAlignment="Center" 
                         ItemsSource="{Binding Items}">
    <telerikGrid:RadDataGrid.Columns>
        <telerikGrid:DataGridTemplateColumn Header="CheckBox">
            <telerikGrid:DataGridTemplateColumn.CellContentTemplate>
                <DataTemplate>
                    <CheckBox Visibility="{Binding IsVisited, Mode=TwoWay}" 
                                    HorizontalAlignment="Center" 
                                    VerticalAlignment="Center"/>
                </DataTemplate>
            </telerikGrid:DataGridTemplateColumn.CellContentTemplate>
        </telerikGrid:DataGridTemplateColumn>
        <telerikGrid:DataGridTextColumn PropertyName="Country" Header="Country"/>
    </telerikGrid:RadDataGrid.Columns>
</telerikGrid:RadDataGrid>

 

and sample viewmodel and business model definitions: 

 

public class Data : INotifyPropertyChanged
{
    private Visibility isvisited;

    public Visibility IsVisited
    {
        get { return this.isvisited; }
        set
        {
            if(this.isvisited!= value)
            {
                this.isvisited = value;
                OnPropertyChanged("IsVisited");
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected void OnPropertyChanged(string name)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(name));
        }
    }
}

public class ViewModel
{
    public ObservableCollection<Data> Items { get; set; }
    public ViewModel()
    {
        this.Items = new ObservableCollection<Data>
        {
            new Data{ IsVisited = Visibility.Collapsed},
            new Data{ IsVisited = Visibility.Visible},
            new Data{ IsVisited = Visibility.Visible},
            new Data{ IsVisited = Visibility.Visible},
            new Data{ IsVisited = Visibility.Collapsed},
            new Data{ IsVisited = Visibility.Visible},
            new Data{ IsVisited = Visibility.Collapsed},
            new Data{ IsVisited = Visibility.Visible},
            new Data{ IsVisited = Visibility.Collapsed},
            new Data{ IsVisited = Visibility.Collapsed},
            new Data{ IsVisited = Visibility.Collapsed},
            new Data{ IsVisited = Visibility.Visible},
            new Data{ IsVisited = Visibility.Visible},
            new Data{ IsVisited = Visibility.Collapsed},
            new Data{ IsVisited = Visibility.Collapsed},
            new Data{ IsVisited = Visibility.Collapsed},
        };
    }
}

I hope this will help.

Regards,
Didi
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Dhanraj
Top achievements
Rank 1
answered on 18 Jun 2020, 07:36 AM

Hi Didi,

Thanks for quick reply.

I have checked with your solution but still I'm facing issue

On loading collapsed checkboxes are invisible but after vertical/Horizontal scrolling all the invisible checkboxes are visible

0
Didi
Telerik team
answered on 18 Jun 2020, 02:57 PM

Hi Dhanraj,

I have just sent a reply in ticket with id: 1471716.

Let me know if I can assist with anything else.

Regards,
Didi
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
DataGrid
Asked by
Dhanraj
Top achievements
Rank 1
Answers by
Didi
Telerik team
Dhanraj
Top achievements
Rank 1
Share this question
or