DatagridView控件添加新增行时触发的事件

编程入门 行业动态 更新时间:2024-10-26 04:27:35

DatagridView<a href=https://www.elefans.com/category/jswz/34/1769529.html style=控件添加新增行时触发的事件"/>

DatagridView控件添加新增行时触发的事件

这两天 给媳妇做了个客户信息管理的小工具,可是有好一段时间没玩过winform开发了,手还有点生了....如下图有这么一个DataGridView控件绑定了数据源,已经设置好允许直接在控件里面增加新行,现在需要给增加新行操作添加相关的处理过程.

需要用到的是DataGridView的NewRowNeeded事件,但是用之前需要先设置DataGridView一个VirtualMode属性为True,主要实现代码如下:

    Private Sub loadDate()ds.Tables.Add("running")ds.Tables.Add("done")adp1.Fill(ds.Tables("running"))adp2.Fill(ds.Tables("done"))Me.BindingSource1.DataSource = ds.Tables("running")Me.BindingSource2.DataSource = ds.Tables("done")Me.RichTextBox1.DataBindings.Add("text", Me.BindingSource1, "detail")Me.RichTextBox2.DataBindings.Add("text", Me.BindingSource2, "detail")Me.DataGridView1.VirtualMode = True    '主要是这一句,上面都是数据初始化的过程End SubPrivate Sub DataGridView1_NewRowNeeded(sender As Object, e As DataGridViewRowEventArgs) Handles DataGridView1.NewRowNeededMsgBox("new row actived")    '这里写增加新行时要处理的过程就好了End Sub

 

更多推荐

DatagridView控件添加新增行时触发的事件

本文发布于:2024-03-23 16:58:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1740607.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   事件   DatagridView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!