Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
VB
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

VB
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
Posted

1 solution

use formclosing event

VB
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
 
Share this answer
 
Comments
ksoftj 7-Apr-13 23:04pm    
Thanks will try today.But I am not closing the main form also if a put the same add & update code in a buuton on form3 or on form1 and pass value to the function in form3 it works.But I want it to be automatic as serial data comes and not manually.

Another thing is that though subroutine doesnt update grid if a close and open form3 it automatically display the addded rows
Atmir 9-Apr-13 17:11pm    
ok then us the dataset events lik of buttons
ksoftj 14-Apr-13 4:30am    
Thanks for your help did try event handling and delegates but no use.Although if I hit the button or open & close form the grid is automatically updates
ksoftj 16-Apr-13 2:14am    
Can i mail the entire program and explain the situation hope u will help.Tired all things like events,delegates and properties but no use. Please help as early as possible.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900