更新datagrid&来自另一个表单的表适配器使用function / sub no按钮 [英] Updating datagrid & table adapter from another form using function/sub no buttons

查看:79
本文介绍了更新datagrid&来自另一个表单的表适配器使用function / sub no按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数据从我的主form1传递到form3中的公共函数,我在其中放置了数据集/ datagrid。此功能接受数据&将行添加到数据集并更新它。但是Datagridview不会自动更新。如果我重新加载表单,它工作正常。它曾经在我设置主键并启用删除和更新命令之前工作。



实际上我将从串口获取传感器数据,这已经配置好了我想要的用串行数据接收事件更新的网格和数据.34.56的值只是一个虚拟来检查使用虚拟端口COM3。(通过com3发送,接收到的串行字节中的34.56的这一部分应该被执行以填充表作为测试。



此前此代码工作正常,但我通过将ID(不在代码中)设置为主键来更改数据集以允许删除并保存它停止工作。我还原如果我按下以下代码(form3)在表单3上执行刷新按钮,它仍然有效。你可以识别问题并解决它。我是vb的新手,所以如果你能详细说明会更好更多可能是代码。

希望快速回复。

I am trying to pass data from my main form1 to a public function in form3 where I have placed the dataset/datagrid. This function accepts the data & adds row to the dataset and updates it. But theDatagridview is not automatically updated. If I reload the form it works fine. It used to work before I set the primary key and enabled delete and update commands.

Actually i will be taking sensor data from serial port which has been configured so i want the grid and data to update with serial data received event.The value of 34.56 is just a dummy to check the working with virtual port COM3.(send via com3 and this part of 34.56 in serial byte received should be executed to fill table as test.

Also earlier this code was working fine but I changed dataset by setting ID (not in code) as primary key to allow delete and save it stopped working .I reverted the changs but no use.It still works if i put a button to perform refresh on form 3 with following code (form3).Can u identify the problem and solve it. I am new to vb so it would be better if you could elaborate more probably with code.
Hoping for quick reply.

Public Class Form3
    Public Sub Update1(ByVal nrow As Double)
        Dim X As DataSet1.SensorOPRow
        X = DataSet1.SensorOP.NewRow
        X.Sensor_Output = nrow
        X.Record_Generated = System.DateTime.Now
        DataSet1.SensorOP.Rows.Add(X)
        SensorOPDataGridView.DataSource = Nothing
        SensorOPBindingSource.EndEdit()
        TableAdapterManager.UpdateAll(DataSet1)
        SensorOPDataGridView.DataSource = DataSet1.SensorOP
        SensorOPTableAdapter.Fill(DataSet1.SensorOP)
    End Sub
...
'In form1
Dim new1 As Double
new1 = 34.56
Form3.Update1(new1)





带按钮





With button

Public Class Form3
    Public Sub Add(ByVal newrw As Double)
        Dim X As DataSet1.SensorOPRow
        X = DataSet1.SensorOP.NewRow
        X.Sensor_Output = newrw
        X.Record_Generated = System.DateTime.Now
        DataSet1.SensorOP.AddSensorOPRow(X)
    End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.TableAdapterManager.UpdateAll(Me.DataSet1)
        Me.SensorOPTableAdapter.Fill(Me.DataSet1.SensorOP)
    End Sub
End Class

推荐答案

使用formclosing事件



use formclosing event

Private Sub form_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

'put code here  to preform action 


    End Sub


这篇关于更新datagrid&来自另一个表单的表适配器使用function / sub no按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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