创建dataGridView
外观属性修改,字体,布局等等.
创建列
插入数据
public class Infovo
{
public string c1 { get; set; }
public string c2 { get; set; }
public string c3 { get; set; }
}
List<Infovo> iv = new List<Infovo>();
iv.Add(new Infovo() { c1 = "h1", c2 = "h2", c3 = "h3" });
iv.Add(new Infovo() { c1 = "t1", c2 = "t2", c3 = "t3" });
iv.Add(new Infovo() { c1 = "t11", c2 = "t22", c3 = "t33" });
iv.Add(new Infovo() { c1 = "t111", c2 = "t222", c3 = "t333" });
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = null;
dataGridView1.DataSource = iv;
添加修改和选中的事件:
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
richTextBox1.Text = "changed!";
}
``
```csharp
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewRow dr= dataGridView1.CurrentRow;
Infovo iftemp = dr.DataBoundItem as Infovo;
richTextBox1.Text = iftemp.c1 + "/" + iftemp.c2 + "/" + iftemp.c3 +";Currentvalue:"+ dataGridView1.CurrentCell.Value;
}
参考:
https://blog.csdn.net/achenyuan/article/details/84632751