更新表格 [英] Updating a table

查看:66
本文介绍了更新表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码使用datagridview,dgvSignlist将信息输入到表中。

I use the code below to input information into a table using the datagridview, dgvSignlist.

这对我来说效果很好,或者至少我对此没有任何问题 但是,我想做一些不同的事情。

This works pretty well for me, or at least I have no problem with this.  However, I would like to do something a little different.

我有一个命名空间,我喜欢使用它来执行例程/函数,以执行下面的工作,使用的是使用此表单类(frmSignList.vb)。 

I have a namespace that I like to use to put routines/functions, to carry out jobs like the one below, that are used with this form class (frmSignList.vb). 

    Private Sub dgvSignList_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvSignList.CellDoubleClick

                'Remove Approver/Trainee from list
                dgvSignList.Rows(e.RowIndex).Cells("chrSignature").Value = CStr("Removed by Change Admin, " & glbstrLogin & " " & CStr(DateAndTime.Now))
                dgvSignList.Rows(e.RowIndex).Cells("blnRemove").Value = 1
                Me.Validate()
                lnkChangeApproveBindingSource.EndEdit()
                LnkChangeApproveTableAdapter.Update(Me._MasterBase_1_0DataSet)
                LnkChangeApproveTableAdapter.FillByChangeID(Me._MasterBase_1_0DataSet.lnkChangeApprove, glbintChangeID) 'refresh DGV

LnkChangeApproveTableAdapter.FillByChangeID(Me._MasterBase_1_0DataSet.lnkChangeApprove, glbintChangeID)

End Sub

对于我的命名空间,我创建了一个类,在类中我有以下例程

For my namespace I created a class and in the class I have the following routine

Public Class CommonRoutines

Public Sub RemoveFromList()

                    'Remove Approver from list
                    CType(frmSignList.lnkChangeApproveBindingSource.Current, DataRowView).Item("chrSignature") = CStr("Removed by Change Admin, " & glbstrAdmin & " " & CStr(DateAndTime.Now))
                    CType(frmSignList.lnkChangeApproveBindingSource.Current, DataRowView).Item("blnRemove") = 1
                    frmSignList.Validate()
                    frmSignList.lnkChangeApproveBindingSource.EndEdit()
                    frmSignList.LnkChangeApproveTableAdapter.Update(frmSignList._MasterBase_1_0DataSet)
                    frmSignList.LnkChangeApproveTableAdapter.FillByChangeID(frmSignList._MasterBase_1_0DataSet.lnkChangeApprove, glbintChangeID) 'refresh DGV

End Sub

End Class

要运行命名空间代码,我只需通过调用命名空间中的例程来替换双击事件中的代码。

To run the namespace code I just replace the code in the double-click event with a call to the routine in the namespace.

当我在命名空间中运行代码时,表格不会随数据一起更新。 我真的认为这应该有效,并且不知道为什么它没有达到与双击事件中的代码相同的结束。

When I run the code in the namespace the table is not updated with the data.  I really had thought that this should work and am at a loss as to why it does not achieve the same end as the code in the double click event.

gwboolean

gwboolean

推荐答案


要运行命名空间代码,我只需通过调用命名空间中的例程来替换双击事件中的代码。

To run the namespace code I just replace the code in the double-click event with a call to the routine in the namespace.

是frmSignList? 您尚未显示设置该变量的代码,以引用您要更新的表单。 它可能在表单的错误实例上执行该代码。  最好的样式会将
形式作为方法的参数传递,因此该方法适用于任何实例。

What is frmSignList?  You haven't shown code that sets that variable to refer to the form that you want to update from.  It is probably executing that code on the wrong instance of the form.   The best style would pass that form as an argument to the method, so that the method is applicable to any instance.


这篇关于更新表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆