Advertisement
megafinz

Untitled

Jan 24th, 2022
1,076
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections.Generic;
  2. using System.Windows.Controls;
  3. using System.Windows.Data;
  4.  
  5. namespace WpfDataGridComboBoxExample;
  6.  
  7. internal sealed class ItemViewModel
  8. {
  9.     public string Gender { get; set; } = "Other";
  10. }
  11.  
  12. internal partial class MainWindow
  13. {
  14.     public MainWindow()
  15.     {
  16.         InitializeComponent();
  17.  
  18.         CreateColumns();
  19.  
  20.         MyDataGrid.ItemsSource = new List<ItemViewModel>
  21.         {
  22.             new(),
  23.             new() { Gender = "Man" }
  24.         };
  25.     }
  26.  
  27.     private void CreateColumns()
  28.     {
  29.         var col = new DataGridComboBoxColumn
  30.         {
  31.             Header = "Gender",
  32.             SelectedValueBinding = new Binding("Gender"),
  33.             ItemsSource = new[] { "Man", "Woman", "Other" }
  34.         };
  35.  
  36.         MyDataGrid.Columns.Add(col);
  37.     }
  38. }
  39.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement