How to bind values to a radtreelistviewgrid column in runtime

6 posts, 0 answers
  1. Chocks
    Chocks avatar
    12 posts
    Member since:
    May 2012

    Posted 09 Aug 2012 Link to this post

    Hi All, I am using Telerik Radtreelistview grid. I have a Checkbox in the screen "Display Code"
    I am assigning the Itemsource to the grid as below mlist.ItemsSource = e.Result.objPrbListView.MasterList; Now the grid is populated.  
    In my Grid I have a column to display code or text with Header like "Code / Text" Based on the checkbox select and unselect I have to display Code or Text in grid column. I will be having both Code and Text in serparately in the observable collection.  How can I bind values to that column based on the checkbox click.  Thanks for any suggestion to code this.
    Regards, V.Chocks. 
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 09 Aug 2012 Link to this post

    Hello,

     Have you tried to define custom CellTemplate for this column or IValueConverter for the DataMemberBinding where you can place your logic?

    All the best,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Chocks
    Chocks avatar
    12 posts
    Member since:
    May 2012

    Posted 10 Aug 2012 Link to this post

    Hi,

    I browsed some samples in forum, but I am not sure that matches this requirement.

    The below Name TextBlock is existing
    <TextBlock Grid.Column="3" Text="{Binding Name}" VerticalAlignment="Center" x:Name="txtName" TextWrapping="Wrap"/>

    now added the below Code TextBlock in XAML. Both TextBlock are in same GridColum.
    <TextBlock Grid.Column="3" Text="{Binding Code}" VerticalAlignment="Center" x:Name="txtCode" TextWrapping="Wrap"/>

    Is it possible to make any one visible based on the CheckBox Click.
    Thanks for any code and suggesstions.


    Regards,
    V.Chocks.
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 10 Aug 2012 Link to this post

    Hello,

     Indeed you can bind the IsCheckec property of the CheckBox to a property in your view-model and you can bind any component Visibility to your view-model property using BooleanToVisibilityConverter.

    All the best,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Chocks
    Chocks avatar
    12 posts
    Member since:
    May 2012

    Posted 10 Aug 2012 Link to this post

    Hi Vlad

    Actually the checkbox is not inside the grid, it is place separately above the grid.
    Is it possible, that i could do this by using Linq or any other binding method which would not affect the performance and change the value in the column. Give any sample code if available. I think I can't implement View Model type, because I dont have 
    separate folders for View and Model.

    I tried something like below, but it seams, it will affect performance, It will be helpful, If i am resolving this by any binding or any other Linq update queries.

     ObservableCollection<PList> lstPrb = mlist.ItemsSource as ObservableCollection<PList>;
                foreach (PList list in lstPrb)
                {
                    if (chkDisplayFreeorCodedText.IsChecked.Value)
                    {
                        list.PrbName = list.FreeText;
                    }
                    else
                    {
                        list.PrbName =  list.Code ;
                    }
                    
                }

    Thanks,
    V.Chocks.
  7. Chocks
    Chocks avatar
    12 posts
    Member since:
    May 2012

    Posted 12 Aug 2012 Link to this post


    Hi,

    The below is working fine when the checkbox is selected, is there any way to check for the Unchecked property to bind.
    I trid by giving !IsChecked as in 2nd TextBlock., it doesnt work. Thanks for any codes.

    <TextBlock Grid.Column="3" Text="{Binding FText}" Visibility="{Binding IsChecked, ElementName=chkDisplayFText}" ></TextBlock>
    <TextBlock Grid.Column="3" Text="{Binding CText}" Visibility="{Binding !IsChecked, ElementName=chkDisplayFText}" ></TextBlock> 



    Thanks,
    V.Chocks.
Back to Top
DevCraft banner