控件添加新增行时触发的事件"/>
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控件添加新增行时触发的事件
发布评论