проблема добавить bindingsource на datagridview
У меня контролл bindingSource1 в конструкторе формы добавляется только на Form1, а на dataGridView1 не добавляется. И поэтому - не могу выбрать "Источник данных" в dataGridView1 как bindingSource1. Подскажите пожалуйста как решить
Я ожидал что контролл bindingSource1 в конструкторе формы добавиться без проблем на dataGridView1 как видно на некоторых роликах
Я так тоже попробовал. Сначала кинул bindingsource, а потом кинул datagridview. Но в datagridview в раскрывающемся списке "Выбрать источник данных" есть только один пункт: "Нет"
namespace WinFormsApp1
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
tableLayoutPanel1 = new TableLayoutPanel();
dataGridView1 = new DataGridView();
btnRefresh = new Button();
bindingSource1 = new BindingSource(components);
tableLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
((System.ComponentModel.ISupportInitialize)bindingSource1).BeginInit();
SuspendLayout();
//
// tableLayoutPanel1
//
tableLayoutPanel1.ColumnCount = 2;
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
tableLayoutPanel1.Controls.Add(dataGridView1, 0, 0);
tableLayoutPanel1.Controls.Add(btnRefresh, 1, 1);
tableLayoutPanel1.Dock = DockStyle.Fill;
tableLayoutPanel1.Location = new Point(0, 0);
tableLayoutPanel1.Name = "tableLayoutPanel1";
tableLayoutPanel1.RowCount = 2;
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
tableLayoutPanel1.RowStyles.Add(new RowStyle());
tableLayoutPanel1.Size = new Size(773, 450);
tableLayoutPanel1.TabIndex = 0;
//
// dataGridView1
//
dataGridView1.AllowUserToAddRows = false;
dataGridView1.AllowUserToDeleteRows = false;
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
tableLayoutPanel1.SetColumnSpan(dataGridView1, 2);
dataGridView1.Dock = DockStyle.Fill;
dataGridView1.Location = new Point(3, 3);
dataGridView1.Name = "dataGridView1";
dataGridView1.ReadOnly = true;
dataGridView1.RowTemplate.Height = 25;
dataGridView1.Size = new Size(767, 415);
dataGridView1.TabIndex = 1;
//
// btnRefresh
//
btnRefresh.Location = new Point(389, 424);
btnRefresh.Name = "btnRefresh";
btnRefresh.Size = new Size(75, 23);
btnRefresh.TabIndex = 0;
btnRefresh.Text = "Refresh";
btnRefresh.UseVisualStyleBackColor = true;
btnRefresh.Click += btnRefresh_Click;
//
// Form1
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(773, 450);
Controls.Add(tableLayoutPanel1);
Name = "Form1";
Text = "Form1";
tableLayoutPanel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
((System.ComponentModel.ISupportInitialize)bindingSource1).EndInit();
ResumeLayout(false);
}
#endregion
private TableLayoutPanel tableLayoutPanel1;
private Button btnRefresh;
private DataGridView dataGridView1;
private BindingSource bindingSource1;
}
}
Источник: Stack Overflow на русском