We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Control visibility of checkbox in sfTreeView nodes

In sfTreeView, I'm showing checkbox in each node by adding following code in ItemTemplate

            <sfTreeView:SfTreeView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <ViewCell.View>
                            <Grid x:Name="grid" Padding="5" RowSpacing="0" BackgroundColor="Transparent">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <sfButton:SfCheckBox IsVisible="{Binding ShowCheckBox, Converter={StaticResource testConverter}}"
                                            x:Name="CheckBox"
                                            IsChecked="{Binding IsChecked, Mode=TwoWay}" 
                                            Text="{Binding Content.SubCategoryName}"
                                            TextColor="Black" 
VerticalOptions="Center"
                                            FontSize="{OnPlatform Android={OnIdiom Phone=16, Tablet=18},iOS={OnIdiom Phone=16,Tablet=18},UWP={OnIdiom Phone=18,Tablet=20,Desktop=20}}"/>
                                <Label Grid.Column="1" Text="{Binding Content.Price}" Margin="3" VerticalOptions="Center"/>
                            </Grid>
                        </ViewCell.View>
                    </ViewCell>

                </DataTemplate>
            </sfTreeView:SfTreeView.ItemTemplate>

Above code shows checkbox on both parent and child node in treeview. However, I want to show checkbox only on child nodes. I have added IsVisible binding as shown in above code but it doesn't control the visibility of checkboxes. How visibility of checkboxes can be controlled through binding?

Regards,


4 Replies

SR Sangeetha Raju Syncfusion Team August 28, 2019 01:15 AM UTC

Hi Krunal, 
 
We would like to inform you that you can achieve your requirement by implementing the different templates using TemplateSelector. We have already updated in our documentation. Please find the documentation for further information. 
 
 
We have prepared a sample for you reference. Please find the sample from the below link. 
 
 
Can you please check with the above sample and let us know whether the provided solution meets your requirement.  
 
Regards, 
Sangeetha Raju. 



KR Krunal August 29, 2019 06:29 AM UTC

@Sangeetha
Thanks for response with example.

I managed to set my treeview node view by following the example given by you. One issue I'm facing with it is IsChecked binding for the checkbox is not working (Template2.xaml) code. I also want to bind the checkbox with property in my viewmodel but upon check/uncheck, property value associated with binding is not updating. Can you pls check and revert back.

Thanks,


KR Krunal August 29, 2019 07:23 AM UTC

I figured out the issue. ItemTemplateContextType was set to "Node" in my code. I changed it to "Item" and now checkbox binding works.


SP Subburaj Pandian Veluchamy Syncfusion Team August 30, 2019 07:32 AM UTC

Hi Krunal,   
   
Thank you for the update. We are happy that the mentioned issue resolved at your end.

Please get in touch with us, if you would require any further assistance.  
 
Regards,
Subburaj Pandian V  


Loader.
Live Chat Icon For mobile
Up arrow icon