Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1.     public partial class Form4 : Form
  2.     {
  3.         private BindingList<test1> bl = new BindingList<test1>();
  4.         public static test2[] values = { new test2("none"), new test2("one"), new test2("two") };
  5.         public Form4()
  6.         {
  7.             InitializeComponent();
  8.  
  9.             //bl.Add(new test1());
  10.  
  11.             dataGridView1.AutoGenerateColumns = false;
  12.             dataGridView1.AutoSize = true;
  13.             dataGridView1.DataSource = bl;
  14.             dataGridView1.Columns.AddRange(getColumn());
  15.  
  16.            
  17.         }
  18.         private DataGridViewColumn getColumn()
  19.         {
  20.             var combo = new DataGridViewComboBoxColumn();
  21.             combo.DataSource = values;
  22.             combo.DataPropertyName = "t2";
  23.             combo.DisplayMember = "s";
  24.             combo.ValueMember = "Value";
  25.             return combo;
  26.         }
  27.     }
  28.  
  29.     public class test1
  30.     {
  31.         private test2 _t2;
  32.  
  33.         public test2 t2
  34.         {
  35.             get
  36.             {
  37.                 return _t2;
  38.             }
  39.             set
  40.             {
  41.                 _t2 = value;
  42.             }
  43.         }
  44.  
  45.         public test1(test2 t2)
  46.         {
  47.             this.t2 = t2;
  48.         }
  49.  
  50.         public test1()
  51.         {
  52.         }
  53.     }
  54.  
  55.     public class test2
  56.     {
  57.         public string s { get; set; }
  58.  
  59.         public test2 Value {
  60.             get { return this; }
  61.         }
  62.  
  63.         public test2(string s = "none")
  64.         {
  65.             this.s = s;
  66.         }
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement