Issue with two way binding in Custom Combobox Template

7 posts, 1 answers
  1. Tiklu
    Tiklu avatar
    11 posts
    Member since:
    Sep 2010

    Posted 23 Nov 2010 Link to this post

    Hi All,
              I am adding a custom combobox template to one of the grids column like this. 

    string controlid = "CustomDrop";
                string SelectedValue = "ContryName";
                string SelectedValuePath = "Name";
                string DisplayMemberPath = "Name";
                var CellTemp = new StringBuilder();
     
                CellTemp.Append(@"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
                                    xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""                                                                         
                                         xmlns:telerikComboBox=""clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"">
                                      <telerikComboBox:RadComboBox x:Name=""" + controlid + @""" DisplayMemberPath=""" + DisplayMemberPath + @"""
                                                SelectedValuePath=""" + SelectedValuePath + @"""                                           
                                                SelectedValue=""{Binding Path=" + SelectedValue + @", Mode=TwoWay}"" ItemsSource=""{Binding Countries, Source={StaticResource CountriesList}}""/>
                                  </DataTemplate>"); //, Mode=TwoWay
               
                grdColumn = new GridViewDataColumn();
                grdColumn.DataMemberBinding = new Binding("ContryName");
                grdColumn.CellTemplate = (DataTemplate)XamlReader.Load(CellTemp.ToString());
                grdColumn.Header = "ContryName";
                RadGridView1.Columns.Add(grdColumn);

    Now Please do note that the itemssource resource is actually in my xaml page. It is not getting called at all by default. So I am explicitly assigning the itemssource to the combobox in the rowloaded event. 

    This thing is working fine when the data is getting loaded for the first time and the combobox is also coming filled with its data. But when I am selecting an item from the combobox. It is again recreating the celltemplate and thus I am loosing the data in the combobox. 

    Please do note that the itemssource of the datagrid and the itemssource of the combobox both implements inotifypropertychanged. And at present I am coding this in SL3. But in case required I can also try implementing this in SL4.

    I hope I was clear about my problem. Any suggestions to fix this issue will be much appreciated.

    Regards
    Tiklu
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 25 Nov 2010 Link to this post

    Hello Tiklu,

    In order to provide you with an appropriate solution, I would need a bit more information about your exact scenario. Where do you define your ComboBox column ? Why don't you use the built-in GridViewComboBoxColumn ? When are you setting the ItemsSource of the grid and the ComboBox ? Is there a particular reason to set it in the RowLoaded event ?
    Please provide any relevant details and code-behind, so that I am aware of your exact settings.
      

    All the best,
    Maya
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. DevCraft banner
  4. Tiklu
    Tiklu avatar
    11 posts
    Member since:
    Sep 2010

    Posted 26 Nov 2010 Link to this post

    Hi Maya,
                
                You can download the whole source code from https://sites.google.com/site/tikluganguly/files . You just need to download the file named 168491_radgridwithingcombobox.rar. Actually in our scenario we needed to have the dropdown permanently visible and not being visible only when we click on the control. Also, in some of the cases we do have dependent dropdowns where on selection of one dropdown the other dropdown need to be populated. 
           The one way we found we can do the dependent dropdown is can be done in Telerik was to use the dropdowncolumn and bind the itemsourcebinding to a property of the business object which we are rendering in the grid.  But in that case we will end up adding one extra unnecessary property in the business object. Also our biggest concern was we wanted the dropdown to be seen in the cells where there is a dropdown.    
           I hope I was been able to clearly describe you my requirement. Awaiting your reply

    Regards
    Tiklu
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 01 Dec 2010 Link to this post

    Hello Tiklu,

    Basically, the way for handling the case with changing the items in a second ComboBox based on the selection in the first one is described in this blog post - I believe you are already familiar with it. The idea behind exposing the AvailableCountries property is that the appropriate collection is saved in case of enabled virtualization and scrolling up and down. When the virtualization is turned on, the visual elements are recycled and the data inside is lost. Once you expose a property for saving it, there should be no problem. 
    In case you do not want to expose a new property, you may set the ItemsSource of the second ComboBox during the SelectionChanged event of the first one, but you need to turn the virtualization off - set the properties EnableColumnVirtualization and EnabledRowVirtualization to false. However, please keep in mind that in case of great amount of data, the performance will be degraded. 

    Best wishes,
    Maya
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  6. Tiklu
    Tiklu avatar
    11 posts
    Member since:
    Sep 2010

    Posted 08 Dec 2010 Link to this post

    Hi Maya,
             Can you please post the blog link. I think in the last reply you missed it :)
    Thanks
    Tiklu
  7. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 08 Dec 2010 Link to this post

    Hi Tiklu,

    You may find the blog post here.
     

    Best wishes,
    Maya
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  8. Tiklu
    Tiklu avatar
    11 posts
    Member since:
    Sep 2010

    Posted 08 Dec 2010 Link to this post

    Hi Maya,
             Thank you for the link..we are going through it right now.

    Regards
    Tiklu
Back to Top
DevCraft banner