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

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

2 Answers 53 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nigel
Top achievements
Rank 1
Nigel asked on 24 Nov 2011, 11:22 AM

//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 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 25 Nov 2011, 09:17 AM
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 >>

0
Nigel
Top achievements
Rank 1
answered on 25 Nov 2011, 12:16 PM
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
Tags
GridView
Asked by
Nigel
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Nigel
Top achievements
Rank 1
Share this question
or