开发者

Adding data to DataGridView

I have datagridview and I want to insert in it values that come from textbox a and a NumericUpDown box but I face a problem which is that these values inserted into the datagridview are not in the column that I specified.

Here is the code I wrote:

        dataGridView1.Rows.Add(MaterialTextBox.Text);
        dataGridView1.Rows.Add(HoursNumericUpDown.Value);
        dataGridView1.Rows.Add(MarkNumericUpDown.Value);
        dataGridView1.Rows.Add(MarkPoints);

and by the way is that way of calculating the values that I get from NumericUpDown box is?

        decimal MarkPoints, x, y;
        x = HoursNumericUpDown.Value;
        y = MarkNumericUpDown.Value;
        MarkPoints开发者_高级运维 = x * y;

Because when I write it with this way I got an error

decimal MarkPoints = HoursNumericUpDown.Value * HoursNumericUpDown.Value;

I think there is no different answer for example let's

HoursNumericUpDown value is 2 
MarkNumericUpDown value is 3 

the answer in the first way is 6 which is correct but the answer in the second way is 4. what is wrong?


you must specify the cells of your row and then add the row to the dataGridView :

    Dim dgvRow As New DataGridViewRow
    Dim dgvCell As DataGridViewCell

    dgvCell = New DataGridViewTextBoxCell()
    dgvCell.Value = MaterialTextBox.Text
    dgvRow.Cells.Add(dgvCell)

    dgvCell = New DataGridViewTextBoxCell()
    dgvCell.Value = HoursNumericUpDown.Value
    dgvRow.Cells.Add(dgvCell)

    dgvCell = New DataGridViewTextBoxCell()
    dgvCell.Value = MarkNumericUpDown.Value
    dgvRow.Cells.Add(dgvCell)

    dgvCell = New DataGridViewTextBoxCell()
    dgvCell.Value = MarkPoints
    dgvRow.Cells.Add(dgvCell)

    dataGridView1.Rows.Add(dgvRow)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜