本文实例讲解C#winform表格控件DataGridView添加数据及获取选中行的值
创建winform添加DataGridView,添加列
修改CS文件代码
using System.Diagnostics;
using System.Windows.Forms;
namespace datagridviewDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//方法一 添加数据
int index = this.dataGridView1.Rows.Add();
this.dataGridView1.Rows[index].Cells[0].Value = "中国";
this.dataGridView1.Rows[index].Cells[1].Value = "台湾";
//方法一 添加数据或控件
DataGridViewRow row = new DataGridViewRow();//创建DataGridView的行对象
DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell();
te