111,120
社区成员
发帖
与我相关
我的任务
分享
namespace WindowsFormsApp1
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.Id = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Name = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Price = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// dataGridView1
//
this.dataGridView1.AllowUserToAddRows = false;
this.dataGridView1.AllowUserToDeleteRows = false;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Id,
this.Name,
this.Price});
this.dataGridView1.Location = new System.Drawing.Point(74, 30);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.ReadOnly = true;
this.dataGridView1.RowTemplate.Height = 23;
this.dataGridView1.Size = new System.Drawing.Size(522, 297);
this.dataGridView1.TabIndex = 0;
//
// Id
//
this.Id.HeaderText = "Id";
this.Id.Name = "Id";
this.Id.ReadOnly = true;
//
// Name
//
this.Name.HeaderText = "Name";
this.Name.Name = "Name";
this.Name.ReadOnly = true;
//
// Price
//
this.Price.HeaderText = "Price";
this.Price.Name = "Price";
this.Price.ReadOnly = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.dataGridView1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.DataGridViewTextBoxColumn Id;
private System.Windows.Forms.DataGridViewTextBoxColumn Name;
private System.Windows.Forms.DataGridViewTextBoxColumn Price;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
var bookList=new List<Book>()
{
new Book{Id=1,Name = "Good Story",Price = 335.2},
new Book{Id=2,Name = "Better Story",Price = 335.2},
new Book{Id=2,Name = "Programer's Story'",Price = 335.2},
new Book{Id=3,Name = "Normal Story",Price = 335.2},
new Book{Id=4,Name = "Good Story",Price = 335.2}
};
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = bookList;
}
}
}