C# winform dataGridView

创建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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值