SHARE
TWEET

Untitled

a guest Jun 19th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Data;
  3. using System.Windows.Forms;
  4.  
  5. namespace WinFormApp1
  6. {
  7.     public partial class Form1 : Form
  8.     {
  9.         DataGridView dataGridView;
  10.         public Form1()
  11.         {
  12.             //InitializeComponent();            
  13.             Width = 500;
  14.  
  15.             var timeTable = new DataTable("timeTable");
  16.             timeTable.Columns.Add("ID_Timetable", typeof(int));
  17.             timeTable.Columns.Add("Date", typeof(DateTime));
  18.             timeTable.Columns.Add("ID_Service", typeof(int));
  19.  
  20.             timeTable.Rows.Add(6, new DateTime(2019, 05, 18));
  21.             timeTable.Rows.Add(7, new DateTime(2019, 05, 17));
  22.             timeTable.Rows.Add(8, new DateTime(2019, 05, 16));
  23.  
  24.  
  25.             var services = new DataTable("services");
  26.             services.Columns.Add("ID_Service", typeof(int));
  27.             services.Columns.Add("Name_service", typeof(string));
  28.  
  29.             services.Rows.Add(1, "Foo");
  30.             services.Rows.Add(2, "Bar");
  31.             services.Rows.Add(3, "Baz");
  32.  
  33.  
  34.             var bindingSourceTimeTable = new BindingSource();
  35.             bindingSourceTimeTable.DataSource = timeTable;
  36.  
  37.             var bindingSourceServices = new BindingSource();
  38.             bindingSourceServices.DataSource = services;
  39.  
  40.  
  41.             var serviceNameColumn = new DataGridViewComboBoxColumn();
  42.             serviceNameColumn.DataSource = bindingSourceServices;
  43.  
  44.             serviceNameColumn.DataPropertyName = "ID_Service"; // внешний ключ
  45.             serviceNameColumn.DisplayMember = "Name_service";            
  46.             serviceNameColumn.ValueMember = "ID_Service"; // первичный ключ
  47.  
  48.  
  49.             dataGridView = new DataGridView { Parent = this, Dock = DockStyle.Top };
  50.             dataGridView.DataSource = bindingSourceTimeTable;
  51.             dataGridView.Columns.Add(serviceNameColumn);
  52.         }
  53.     }
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top