vb.net从另一个userform更新datagridview [英] vb.net update datagridview from another userform

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

问题描述

你好



我有一个带有datagridview的userform,它映射到访问中的数据库。我想要的是,一旦你点击datagridview显示一个userform,其中包含所选行的值,并且能够从userform更新并保存

解决方案

follow exert将解释如何从datagridview单元格双击获取值。



您是否需要能够从用户表单更新数据库或更新数据库更新datagridview中显示的值?





 私有  Sub  DataGridView1_CellDoubleClick(发件人作为 对象,e  As  System.Windows.Forms.DataGridViewCellEventArgs)句柄 DataGridView1.CellDoubleClick 
Dim CellValueA 作为 字符串 = Nothing
Dim CellValueB As 字符串 = 没什么

CellValueA = DataGridView1.Rows(DataGridView1.CurrentRow.Index )。细胞( 0 )。Value.ToString
CellValueA = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells( 1 )。Value.ToString

Dim ofrm As Form2(CellValueA,CellValueB)
ofrm.show()

结束 Sub


下面的代码将向您展示如何获取从FORM1到textbox的datagridview数据FORM2



私有子DataGridViewX1_DoubleClick(发件人作为对象,e作为系统.EventArgs)处理DataGridViewX1.DoubleClick

FORM2.textbox1.Text = DataGridViewX1.CurrentRow.Cells(1).Value.ToString

FORM2.textbox2.Text = DataGridViewX1.CurrentRow .Cells(2).Value.ToString

End Sub



你可以使用sql update语句完成更新:



EditRepInvSave.CommandText =UPDATE [Repair_Inventory] ​​set [User] ='&textbox1.Text.Trim&'where id ='&textbox2.text.trim& '


请参阅我专门针对此类案例撰写的文章:一次回答的许多问题 - Windows窗体或WPF Windows之间的协作 [ ^ ]。



-SA

Hello

I have a userform with a datagridview and its mapped to a database in access. What I want is to, once you click the datagridview to display a userform with the values from the selected row and the to be able to update from the userform and save

解决方案

The follow exert will explain how to obtain the values from a datagridview cell double click.

do you need to be able to update the database from the user form or to update the displayed values in the datagridview?


Private Sub DataGridView1_CellDoubleClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
       Dim CellValueA As String = Nothing
       Dim CellValueB As String = Nothing

       CellValueA = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(0).Value.ToString
       CellValueA = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(1).Value.ToString

       Dim ofrm As New Form2(CellValueA, CellValueB)
       ofrm.show()

   End Sub


Below code will show you how to get data from datagridview from FORM1 to textbox FORM2

Private Sub DataGridViewX1_DoubleClick(sender As Object, e As System.EventArgs) Handles DataGridViewX1.DoubleClick
FORM2.textbox1.Text = DataGridViewX1.CurrentRow.Cells(1).Value.ToString
FORM2.textbox2.Text = DataGridViewX1.CurrentRow.Cells(2).Value.ToString
End Sub

And you can accomplish update by using sql update statement :

EditRepInvSave.CommandText = "UPDATE [Repair_Inventory] set [User] = '" & textbox1.Text.Trim & "' where id = '" & textbox2.text.trim & "'"


Please see my article written specially for such cases: Many Questions Answered at Once — Collaboration between Windows Forms or WPF Windows[^].

—SA


这篇关于vb.net从另一个userform更新datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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