Edited text in telerik:GridViewComboBoxColumn fails to write to bound data object using ItemsSource , otherwise works fine.

3 posts, 0 answers
  1. Nigel
    Nigel avatar
    2 posts
    Member since:
    Nov 2011

    Posted 24 Nov 2011 Link to this post

    //PROBLEM: Edited text in telerik:GridViewComboBoxColumn fails to write to bound data object using ItemsSource , otherwise works fine.

    //  The drop down list works fine but when i try to enter some text into the editor it doesn't write to the Path property on my CinemaPackage. In fact it looks like it is trying to bind to 'Path' proerty on my ViewModel 

    public class CinemaPackage : NotifyPropertyChangedBase

    {

                    private string path;

                    public CinemaPackage()

                    {

                                    Paths = new ObservableCollection<string> {"path1", "path2"};

                    }

                     public ObservableCollection<string> Paths { get; set; }

     

                    public string Path

                    {

                                    get { return path; }

                                    set

                                    {

                                                    path = value;

                                                    ViewModelPropertyChanged(this, "Path");

                                    }

                    }

    }

      

    public class TransferPackagesViewModel : ViewModelAppBase, ITransferPackagesViewModel

    {

                    public ObservableCollection<CinemaPackage> CinemaPackages { get; set; }

                     public TransferPackagesViewModel()                                              

                    {

                                    CinemaPackages = new ObservableCollection<CinemaPackage>();

                    }

                                  

                    // this should not be needed here

                    //private string path;

                    //public string Path

                    //{

                    //    get { return path; }

                    //    set

                    //    {

                    //        path = value;

                    //        ViewModelPropertyChanged(this, "Path");

                    //    }

                    //}

    }

     

     

    <UserControl

                    x:Class="Flix.SupplyChain.CinemaLibrary.Views.TransferPackagesView"

                    xmlns:telerikData="clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data"

    >

                                     <telerik:RadGridView

                                                    Name="RadGridView1"

                                                    ItemsSource="{Binding Path=CinemaPackages, Mode=TwoWay}"

                                                                                    >

                        <telerik:RadGridView.Columns>

                                                                                    <telerik:GridViewComboBoxColumn

                                                                                                    ItemsSource ="{Binding Path, Mode=TwoWay}"

                                                                                                    ItemsSourceBinding="{Binding Paths}"

                                                                                                    DataMemberBinding="{Binding Path }"

                                                                                                    IsComboBoxEditable="True"

                                                                                                    UniqueName="ExportPath"

                                                                                 />

     

    </telerik:RadGridView.Columns>

    </telerik:RadGridView>

     </UserControl>

      

    OUTPUT:

    System.Windows.Data Error: BindingExpression path error: 'Path' property not found on 'Flix.SupplyChain.CinemaLibrary.TransferPackagesViewModel' 'Flix.SupplyChain.CinemaLibrary.TransferPackagesViewModel' (HashCode=58543024). BindingExpression: Path='Path' DataItem='Flix.SupplyChain.CinemaLibrary.TransferPackagesViewModel' (HashCode=58543024); target element is 'Telerik.Windows.Controls.GridViewComboBoxColumn' (Name='null'); target property is 'ItemsSource' (type 'System.Collections.IEnumerable')..

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 25 Nov 2011 Link to this post

    Hi Nigel,

    Unfortunately from those code snippets I could not guess what would be wrong with your ItemsSource.

    That is why I have created a sample application, showing how the GridViewComboBoxColumn could be edited. I hope that getting through it will give you a hint on how to resolve your binding error. 

    Please let me know if this helps.

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. Nigel
    Nigel avatar
    2 posts
    Member since:
    Nov 2011

    Posted 25 Nov 2011 Link to this post

    We found a solution to the problem

    <telerik:RadGridView
        CellEditEnded="RadGridView1_CellEditEnded"
     />

    private void RadGridView1_CellEditEnded(object sender,  GridViewCellEditEndedEventArgs e)
    {
      //+ get export paths comobo box
      RadComboBox cb = e.Cell.ChildrenOfType<RadComboBox>().ToList()[0];
      
      string textEntered = cb.Text;
     
      var cp = cb.DataContext as CinemaPackage;

      if (string.IsNullOrEmpty(textEntered) || cp.Paths.Contains(textEntered, StringComparer.OrdinalIgnoreCase))
       return;
     
      cp.Paths.Add(textEntered);

      cp.Path = textEntered;
    }


    // the problem is that the combo box doesn't know how to create a new row in the list
Back to Top