I ve got a program which starts with welcome screen "Enter the number of the random variables X" and this number refers to the columns. If it is entered 5 => a DataGridView
will be created with 5 columns and 2 rows (first one is for random variable entered by the user, and the second is for probability). For example:
X 1 2 3 4 5 6
p 2 2 2 2 2 2
页: 1 So EX = x1*p1 + x2*p2 +...
这里的问题是:如何乘数,然后添加?
There are only 2 rows, that s how much I need :
I ve enabled only 2 rows, that s how much I must have for this program:
Const allowedRows As Integer = 2
Private Sub DataGridView1_UserAddedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles DataGridView1.UserAddedRow
DataGridView1.AllowUserToAddRows = DataGridView1.RowCount <= allowedRows
End Sub
Private Sub DataGridView1_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles DataGridView1.UserDeletedRow
DataGridView1.AllowUserToAddRows = DataGridView1.RowCount <= allowedRows
End Sub
The loop is:
For j = 0 To DataGridView1.Columns.Count
For i As Integer = 0 To DataGridView1.RowCount - 1
multi = CInt(DataGridView1.Rows(i).Cells(j).Value) * CInt(DataGridView1.Rows(i).Cells(j).Value)
Next
EX += multi
Next
我认为,它必须如此(它给OfRange例外),但我为什么在这里写字,这样,如果任何人知道如何做,我就非常感激。 提前感谢。