DataGridComboBoxColumn binding via SelectedValueBinding and SelectedValuePath

I have been working on dummy project to understand binding in DataGridComboBoxColumn and in that I have encountered to SelectedValuePath and SelectedValue Binding.
I have looked up to various source of other questions too to understand such as follows
to understand bindings
and this,
and at last this too

the problem in my code is it gets bonded with SelectedItemBinding but not with SelectedValuePath & SelectedValueBinding

using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace WpfApplication10
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            DataContext = new MainViewModel();



        }

   
    }


    public class Item
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Code { get; set; }

        // Property for the composite value
        public string CombinedValue => $"{ID}_{Name}_{Code}";
    }

    public class MainViewModel : INotifyPropertyChanged
    {
        

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        private Item _selectedItem;
        public Item SelectedItem
        {
            get { return _selectedItem; }
            set
            {
                if (_selectedItem != value)
                {
                    _selectedItem = value;
                    OnPropertyChanged(nameof(SelectedItem));
                }
            }
        }

       
        

        public ObservableCollection<Item> Items { get; set; }
        public ObservableCollection<string> Codes { get; set; }

        public MainViewModel()
        {
            Items = new ObservableCollection<Item>
        {
            new Item { ID = 1, Name = "Item 1", Code = "A" },
            new Item { ID = 2, Name = "Item 2", Code = "Z" },
            new Item { ID = 3, Name = "Item 3", Code = "C" },
            new Item { ID = 4, Name = "Item 4", Code = "A C" }
        };
            Codes = new ObservableCollection<string>(Items.Select(item => item.Code).Distinct());
            SelectedItem = Items.FirstOrDefault();
        }

        
    }
}

I have tried below with SelectedItemBinding and it works

<DataGridComboBoxColumn Header="Code" SelectedItemBinding="{Binding Code}" Width="100" IsReadOnly="True">
                    <DataGridComboBoxColumn.ElementStyle>
                        <Style TargetType="ComboBox">
                            <Setter Property="ItemsSource" Value="{Binding DataContext.Codes, 
                                RelativeSource={RelativeSource AncestorType=Window}}"/>
                        </Style>
                    </DataGridComboBoxColumn.ElementStyle>
                    
                </DataGridComboBoxColumn>

but I want to implement above with SelectedValueBinding & SelectedValuePath

I have tried this till now

<DataGridComboBoxColumn Header="Value-Binded" ItemsSource="{Binding DataContext.Items}"
                                        SelectedValuePath="Code"
                                        SelectedValueBinding="{Binding ID , UpdateSourceTrigger=PropertyChanged}"
                                        >                   
                </DataGridComboBoxColumn>

DataGrid Defined as

 <DataGrid ItemsSource="{Binding Items}" AutoGenerateColumns="False" CanUserAddRows="False">

And DataContext as

<Window.DataContext>
        <local:MainViewModel/>
    </Window.DataContext>

New contributor

Pushkar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật