Click here to Skip to main content
15,906,626 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
For the project I am suppose to have a datagridview, and two charts with a button in the first window. Then you click a button to add a sample (group of five with five different text boxes, tbUno.Text, etc) in the other windows forum called Values. I then click another button to enter the data I just put in the Values window forum into the VariableControl forum in the datagridview. They are entered in as five different columns. The two charts are XBar charts and Range charts. I already have it coded so that the average of the five entries I just made automatically makes a point in the XBar chart (of those values average) and in the Range chart (of those values range). In the datagrid view you can enter unlimited amount of data. Now I need to find the average of all of the averages entered in the datagridview that are plotted on the XBar chart, and I need to input them on that same chart for the center line. I also need to find the average of all of the ranges plotted in the Range chart and then plot that average in the range chart for the center line as well. In addition, I need to be able to use those values of the average of the averages and the average of the ranges in order to solve for different equations. I think I need to declare two addition arrays as class members but I wasn't sure if I was doing right or how to really.



Updated code from previously so it is cleaner.


VB
Public Class VariableControl
    Dim array_of_all_values As Object
    Dim NumCol, NumRow As Integer

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        Try
            If Values.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim MyArray(4) As Double

                MyArray(0) = Values.tbUno.Text
                MyArray(1) = Values.tbDos.Text
                MyArray(2) = Values.tbTres.Text
                MyArray(3) = Values.tbCuatro.Text
                MyArray(4) = Values.tbCinco.Text

                dgvValues.Rows.Add(MyArray(0), MyArray(1), MyArray(2), MyArray(3), MyArray(4))

                chXBar.Series(0).Points.Add(MyArray.Average)

                chRange.Series(0).Points.Add(MyArray.Max - MyArray.Min)


                chXBar.ChartAreas(0).AxisY.IsStartedFromZero = False
                chRange.ChartAreas(0).AxisY.IsStartedFromZero = False
            End If
        Catch ex As Exception
            MsgBox("Please enter in numeric values.")
        End Try
    End Sub


End Class







Thank you so much for any help!
Posted
Updated 6-Jun-15 8:25am
v5
Comments
Ralf Meier 6-Jun-15 6:30am    
I'm sorry but I can't understand your problem (because of your description).
Please explain once more step by step what you want to do, what is working and where is the problem.

If I understood right you add values to the DGV. For each column you want to build the average. If I'm right, this could be done by iterating through all Items inside the column.

Please give more Information ...
Member 11745645 6-Jun-15 14:21pm    
Apologies. I've cleaned up the code to now look like the one below. For the project I am suppose to have a datagridview, and two charts with a button in the first window. Then you click a button to add a sample (group of five with five different text boxes, tbUno.Text, etc) in the other windows forum called Values. I then click another button to enter the data I just put in the Values window forum into the VariableControl forum in the datagridview. They are entered in as five different columns. The two charts are XBar charts and Range charts. I already have it coded so that the average of the five entries I just made automatically makes a point in the XBar chart (of those values average) and in the Range chart (of those values range). In the datagrid view you can enter unlimited amount of data. Now I need to find the average of all of the averages entered in the datagridview that are plotted on the XBar chart, and I need to input them on that same chart for the center line. I also need to find the average of all of the ranges plotted in the Range chart and then plot that average in the range chart for the center line as well. In addition, I need to be able to use those values of the average of the averages and the average of the ranges in order to solve for different equations. I think I need to declare two addition arrays as class members but I wasn't sure if I was doing right or how to really.


Public Class VariableControl
Dim array_of_all_values As Object
Dim NumCol, NumRow As Integer

Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
Try
If Values.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim MyArray(4) As Double

MyArray(0) = Values.tbUno.Text
MyArray(1) = Values.tbDos.Text
MyArray(2) = Values.tbTres.Text
MyArray(3) = Values.tbCuatro.Text
MyArray(4) = Values.tbCinco.Text

dgvValues.Rows.Add(MyArray(0), MyArray(1), MyArray(2), MyArray(3), MyArray(4))

chXBar.Series(0).Points.Add(MyArray.Average)

chRange.Series(0).Points.Add(MyArray.Max - MyArray.Min)
'Series(1) for each of the charts will be the center line, I then also need the upper control limit and lower control limit which I cannot plot until I have the center line values of each of the charts.


chXBar.ChartAreas(0).AxisY.IsStartedFromZero = False
chRange.ChartAreas(0).AxisY.IsStartedFromZero = False
End If
Catch ex As Exception
MsgBox("Please enter in numeric values.")
End Try
End Sub


End Class

Ralf Meier 7-Jun-15 8:35am    
I try to describe it with my words (step by step).
At first :
You have a Form or a Dialog where you enter the value (into Textboxes).
You press a Button and the entered Values are written into the DGV.
Also the Average-Value of the entered Values is written as new Point to the BarChart (and the RangeChart ?)
Now you want to build up the Average of ALL Values, entered in the DGV, to create a seperate Line inside the RangeChart ? At the same Time you want to know the absolute min.-Value and the asolute max.-Value for the same Chart for the scaling of the Y-Axis ?

If I'm right with this summary then you have to iterate through all the values in the DGV to build the average and to find the limits.
Or ... what I think which is much better : you do it every time when a Value is entered to the DGV and memorize the result.
Do you need a suggestion or an example for this ?

Or am I complete wrong with my summary ...?
Member 11745645 7-Jun-15 18:10pm    
You got most of it right. I'm trying to find the average of all of the averages in the first chart (xBar), and then the average of all of the ranges in the second chart (Range). I know how to do the max and min. I'm just not sure how to construct the code to copy each array I entered into the textboxes into another array....

I wanted to take all of the averages from the first chart--and copy them into an array member class (Dim XBarVal As Double={}) and then I wanted to take all of the ranges from the second chart and copy them into a separate array member class (Dim RangeVal As Double={}).

I need an example, I'm just not sure how to get the syntax to copy the data points into another array correctly.

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