Click here to Skip to main content
14,837,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm looking for a way to get the scores of the students which are in the scores column in a data grid view which is bound with access and is in my view all data form to go to a timer which is in another form that will use that data to graph the scores on a chart.

I have googled pretty much everything that would come to mind but nothing either related to my problem or worked.

So if somebody can help me out, that would be awesome because I literally have no idea what to do!!

What I have tried:

I tried this from something I found on google:

I created a shared class...

Public Class dgvUserData
Public Shared Dt As New DataTable
Public Shared Bs As New BindingSource

End Class

On the view all data form I coded:

Public Class frmViewAllData
    Sub LoadData()
    SharedClass.Dt =
    SharedClass.Bs.DataSource = SharedClass.Dt
    dgvUserData.Datasource = SharedClass.Bs
    End Sub
    End Class

On the form that had the timer and chart I coded:

Public Class frmMonitorHeartRate
    Sub LoadData()
    dgvUserData.DataSource = SharedClass.Bs
    End Sub
    End Class
Updated 4-Aug-20 22:39pm

For starters, you shouldn't be using Shared for this - it's a bad idea.

Instead, you should create a property in your frmMonitorHeartRate which your frmViewAllData uses to pass the source DataTable to it (assuming that the frmMonitorHeartRate instance is created by frmViewAllData, which you don't show).

Then in the frmViewAllData timer, you can peruse the DataTable (by using a For Each on the Rows property, and accessing each rows Cell(indexOfDataColumnYouAreIntestedIn) to get the two data items you need for your chart - the X and Y values - and display them in your chosen Chart.

Sounds complicated? It isn't, not really. It's just a case of getting your head around how things work!
Have a look at these.

The form that creates an instance of another:
MyForm mf = new MyForm();
Is the "parent", the other form is the "child".
(This doesn't imply any formal MDI relationship)

Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]

The code is in C#, but it's pretty obvious, and Code Converter C# to VB and VB to C# – Telerik[^] will convert anything you can't cope with.
You should only need the first one, but since I have no idea how your app works, it's possible the other two will help as well.
Merscy 10-Aug-20 20:55pm
Hi there,
I tried those but they didn't work
OriginalGriff 11-Aug-20 1:37am
They clearly do work, the demo code runs fine.
So the problem is clearly with how you implemented them ... and we have no idea what you did!
Merscy 11-Aug-20 4:28am
Hi there,
sorry I wasn't trying to be rude or anything. Yes, you're right, the problem is with me as I think I could not tell which one related to mine and how I should implement them. I'm sorry this is probably frustrating, but if it's possible could you please tell me which one is which?

So pretty much, the frmMonitorHeartRate is the form that receives all the user input and the frmViewAllData is the form that has a dgvUserData which is a data table that shows all of the data that the user has entered. However, going back to frmMonitorHeartRate, there is a timer and a graph in there and I would like all the scores from the data table (dgvUserData) in the other form to be transferred to the timer in frmMonitorHeartRate. Once I manage to do that I've pretty much done the coding part for the timer to transfer the data to the chart, however, I'm not sure within the timer if I should mention dgvUserData (the name of the data table from the other form) or not. So with what I tried it kept on giving errors with when I mentioned the object like the timer or the dgvUserData or the parts where you give the codes about the form.

If you could help me out with figuring those out that would be great!!

I'm sorry for being a pain and thank you very much for your time already though. I wish I knew if there was actually a way to actually show you what's my problem at the start.
OriginalGriff 11-Aug-20 5:05am
So which form creates and displays the other?
Merscy 11-Aug-20 6:06am
umm, I'm not really sure what you mean, but the data table (dgvUserData) from the frmViewAllData form receives the user input from the frmMonitorHeartRate form...
OriginalGriff 11-Aug-20 6:28am
Somewhere in your code there are lines like this:
Form2 f2 = new Form2();
Or it may be Form1 instead.
Find that, and you'll know which is the "parent"
Merscy 11-Aug-20 6:32am
Wait are these things that you talk about in visual basics?? I have a feeling you're talking in C# and they may be different in that aspect...
OriginalGriff 11-Aug-20 6:58am
It's the same process, the same calls regardless of VB or C# - there are even online converters to translate them:
For example.

In a childish language, my last code sample would be:
Dim f2 As New Form2

See what I mean?
Merscy 11-Aug-20 7:17am
Oh yes, I understand what you mean but I can't find anything like that. Sorry, I feel so dumb, was I meant to implement that in or is it meant to already be there? Because if I was meant to implement that in, it would give me an error and if it was meant to be already there well then I couldn't find it...
OriginalGriff 11-Aug-20 7:46am
You have two forms visible, yes?
So one will (probably) be opened for you automatically, the second you had to open for yourself. Which requires a call to either Show or ShowDialog on an instance of the form. So think: when does the second form open? Where did you tell it to do that?
Merscy 11-Aug-20 8:18am
oh yes, I get you. In that case, the second form is frmViewAllData. As you need to press a button in frmMonitorHeartRate to get to frmViewAllData, and in the first form (frmMonitorHeartRate) I did:

Private Sub btnViewAllData_Click(sender As Object, e As EventArgs) Handles btnViewAllData.Click
End Sub

However, just so you know, I also do have a main menu form which just takes the user to both frmMonitorHeartRate and frmViewAllData.
OriginalGriff 11-Aug-20 8:28am
That's the one!
So AllData is the child: Create a property in there that returns a DataTable and fill it when the Getter is used.
Then all you need to do is use the current instance of the form to access it:

Dim dt As DataTable = frmViewAllData.GetData

Use that in the timer and see if it does what you want!
Merscy 11-Aug-20 18:22pm
Hey there,

Thank you. I think all is good but there is an error within the timer, which I'm guessing it's because I did those coding before I did all this. What do you think I should do about it?

Here is the code:

Private Sub tmrMonitor_Tick(sender As Object, e As EventArgs) Handles tmrMonitor.Tick
Dim dt As DataTable = frmViewAllData.GetdgvUserData
Dim a As Integer
If counter < dgvUserData.RowCount Then
Integer.TryParse(dgvUserData.Rows(counter).Cells(0).Value, a)

lblPulseValue.Text = a.ToString()
If (a > max) Then
ElseIf (a < min) Then
End If
counter = counter + 1
chrtDaily.Series("Beats Per Minute").Points.AddY(a.ToString)
End If
End Sub

These lines were the ones with the error:

If counter < dgvUserData.RowCount Then
Integer.TryParse(dgvUserData.Rows(counter).Cells(0).Value, a)

The error is with the dgvUserData ones and I tried replacing them with dt but that didn't help as well...
OriginalGriff 12-Aug-20 2:01am
Go back to the documentation of TryParse and compare the example to your code...
Ok, it looks like you now need to load this
Dt As New DataTable
data-table from the access database - there's a clue or so here sql - Loading Images from Access Database to DataTable? - Stack Overflow[^]
Merscy 10-Aug-20 20:54pm
Hi there,

I tried it but it didn't work
Garth J Lancaster 10-Aug-20 23:31pm
That sort of response, to myself and OG (the other solution), is about as useful as tits on a boar - OG's solution in particular does work depending on the relationship between the forms - parent-child etc .. maybe you should update your question with your coding as per OG's notes - use Improve question
Merscy 11-Aug-20 4:41am
Hi there,

Yes, I understand and sorry about that. You are right and I wasn't trying to be rude or anything and I know it may be frustrating but I've tried explaining why they didn't work for me in OG's reply and if you could please help me out with that, that would be great. I'm pretty sure I tried every one of those but it kept on giving errors with the recognising part I think... Also thanks for your time already as well...

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