Welcome to the Xceed Community | Help
Community Search  
More Search Options

Combo box selected value is not getting saved in grid cell

Sort Posts: Previous Next
  •  07-21-2009, 3:23 PM Post no. 22773

    Combo box selected value is not getting saved in grid cell

    I have a combo box in a grid cell which populates data from collection. However, it's value is not getting saved in the grid cell when focus is moved to another row in the grid. Any pointers would be greatly appreciated.
  •  07-21-2009, 3:26 PM Post no. 22774 in reply to 22773

    Re: Combo box selected value is not getting saved in grid cell

    Are you binding the SelectedValue property using a CellEditorBinding? If not, that is most likely the cause of the behavior you are experiencing.
    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  07-21-2009, 4:47 PM Post no. 22778 in reply to 22774

    Re: Combo box selected value is not getting saved in grid cell

    Hi Jenny,

    I am binding the SelectedValue property using a CellEditorBinding. However, not sure if that's correct. Here is the code -

    DataGridCollectionView theView = new DataGridCollectionView(roomsListNew, typeof(ExchangeRoomResource), false, false);

    theView.DetailDescriptions.Add(new ParentDetailDescription());

    Binding binding = new Binding();

    binding.Source = roomsConflictList;

    //binding.Mode = BindingMode.TwoWay;

    //binding.Path = ???

    //binding.UpdateSourceTrigger = ???

    DataTemplate myEditorTemplate = new DataTemplate();

    myEditorTemplate.VisualTree = new FrameworkElementFactory(typeof(ComboBox));

    myEditorTemplate.VisualTree.SetValue(ComboBox.ItemsSourceProperty, binding);

    myEditorTemplate.VisualTree.SetValue(ComboBox.SelectedValuePathProperty, "AlternateRoomName");

    myEditorTemplate.VisualTree.SetValue(ComboBox.DisplayMemberPathProperty, "AlternateRoomName");

    Xceed.Wpf.DataGrid.Markup.CellEditorBindingExtension cellbinding = new Xceed.Wpf.DataGrid.Markup.CellEditorBindingExtension();

    myEditorTemplate.VisualTree.SetBinding(ComboBox.SelectedValueProperty, (BindingBase)cellbinding.ProvideValue(null));

    CellEditor cellEditor = new CellEditor();

    cellEditor.EditTemplate = myEditorTemplate;

    this.ctlSearchResults.DetailConfigurations["ConflictDetailRelation"].Columns["SuggestedRoomName"].CellEditor = cellEditor;

    DataTemplate myCellContentTemplate = new DataTemplate();

    myCellContentTemplate.VisualTree = new FrameworkElementFactory(typeof(TextBlock));  //????

    myCellContentTemplate.VisualTree.SetValue(TextBlock.TextProperty, binding);    //????

    this.ctlSearchResults.DetailConfigurations["ConflictDetailRelation"].Columns["SuggestedRoomName"].CellContentTemplate = myCellContentTemplate;

    this.ctlSearchResults.ItemsSource = theView;

  •  07-21-2009, 10:20 PM Post no. 22783 in reply to 22778

    Re: Combo box selected value is not getting saved in grid cell

    myCellContentTemplate.VisualTree.SetValue(TextBlock.TextProperty, binding); 

    change to

    myCellContentTemplate.VisualTree.SetValue(TextBlock.TextProperty, cellbinding ); 

  •  07-22-2009, 1:47 PM Post no. 22812 in reply to 22783

    Re: Urgent: Combo box selected value is not getting saved in grid cell

    This is Urgent. Pls help. Changing to cellbinding didn't work. Please help. Here is the code -

    DataGridCollectionView theView = new DataGridCollectionView(roomsListNew, typeof(ExchangeRoomResource), false, false);

    theView.DetailDescriptions.Add(new ParentDetailDescription());

    List<ExchangeRoomConflictData> roomsConflictList = new List<ExchangeRoomConflictData>();

    roomsConflictList.Add(new ExchangeRoomConflictData(DateTime.Today.AddMonths(1), "Dynamic Data: Room 1"));

    roomsConflictList.Add(new ExchangeRoomConflictData(DateTime.Today.AddMonths(2), "Dynamic Data: Room 2"));

    roomsConflictList.Add(new ExchangeRoomConflictData(DateTime.Today.AddMonths(3), "Dynamic Data: Room 3"));

    Binding binding = new Binding();

    binding.Source = roomsConflictList;

    DataTemplate myEditorTemplate = new DataTemplate();

    myEditorTemplate.VisualTree = new FrameworkElementFactory(typeof(ComboBox));

    myEditorTemplate.VisualTree.SetValue(ComboBox.ItemsSourceProperty, binding);

    myEditorTemplate.VisualTree.SetValue(ComboBox.SelectedValuePathProperty, "AlternateRoomName");

    myEditorTemplate.VisualTree.SetValue(ComboBox.DisplayMemberPathProperty, "AlternateRoomName");

    Xceed.Wpf.DataGrid.Markup.CellEditorBindingExtension cellbinding = new Xceed.Wpf.DataGrid.Markup.CellEditorBindingExtension();

    myEditorTemplate.VisualTree.SetBinding(ComboBox.SelectedValueProperty, (BindingBase)cellbinding.ProvideValue(null));

    CellEditor cellEditor = new CellEditor();

    cellEditor.EditTemplate = myEditorTemplate;

    this.ctlSearchResults.DetailConfigurations["ConflictDetailRelation"].Columns["SuggestedRoomName"].CellEditor = cellEditor;

    Binding cellcontentbinding = new Binding();

    cellcontentbinding.Source = roomsConflictList;

    cellcontentbinding.Mode = BindingMode.TwoWay;

    cellcontentbinding.Path = new PropertyPath("AlternateRoomName");

    cellcontentbinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;

    DataTemplate myCellContentTemplate = new DataTemplate();

    myCellContentTemplate.VisualTree = new FrameworkElementFactory(typeof(TextBlock));

    myCellContentTemplate.VisualTree.SetValue(TextBlock.TextProperty, cellcontentbinding);

    this.ctlSearchResults.DetailConfigurations["ConflictDetailRelation"].Columns["SuggestedRoomName"].CellContentTemplate = myCellContentTemplate;

    this.ctlSearchResults.ItemsSource = theView; // ctlSearchResults is Xceed WPF grid control

  •  08-16-2010, 5:45 AM Post no. 27982 in reply to 22812

    Re: Urgent: Combo box selected value is not getting saved in grid cell

    Hi Xceed Team,

    I am facing the same problem.

    Please tell the solution of this problem.

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.