首页| JavaScript| HTML/CSS| Matlab| PHP| Python| Java| C/C++/VC++| C#| ASP| 其他|
购买积分 购买会员 激活码充值

您现在的位置是:虫虫源码 > 其他 > 关于datagridview控件的简单例子,更容易理解一些

关于datagridview控件的简单例子,更容易理解一些

  • 资源大小:0.12M
  • 上传时间:2021-07-18
  • 下载次数:0次
  • 浏览次数:1次
  • 资源积分:1积分
  • 标      签: C#语言基础

资 源 简 介

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace DataGridViewSample{ public partial class Form1 : Form { public static List Tests = new List(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.dataGridView1.DataSource = Tests; } private void button1_Click(object sender, EventArgs e) { frmAdd form = new frmAdd(null); if (form.ShowDialog() == DialogResult.OK) { this.dataGridView1.DataSource = null; this.dataGridView1.DataSource = Tests; } } private void button2_Click(object sender, EventArgs e) { if (this.dataGridView1.SelectedRows != null) { frmAdd form = new frmAdd(new Test( Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells[0].Value), Convert.ToDecimal(this.dataGridView1.SelectedRows[0].Cells[1].Value), Convert.ToDateTime(this.dataGridView1.SelectedRows[0].Cells[2].Value), this.dataGridView1.SelectedRows[0].Cells[3].Value.ToString())); if (form.ShowDialog() == DialogResult.OK) { this.dataGridView1.DataSource = null; this.dataGridView1.DataSource = Tests; } } } private void button3_Click(object sender, EventArgs e) { //使用前面示例中的代码,用DataGridView或者List来做导出都是可以的 } } public class Test { public Test(int id, decimal voltage, DateTime record, string remark) { ID = id; Voltage = voltage; Record = record; Remark = remark; } public int ID { get; set; } public decimal Voltage { get; set; } public DateTime Record { get; set; } public string Remark { get; set; } }}

相 关 资 源

您 可 能 感 兴 趣 的

同 类 别 推 荐

VIP VIP