Hi Everyone.

I got a problem when I want to input data into my second row. whenever i try to insert data,the data always appeared in the row.
here's my code...

private void btnTambahStock_Click(object sender, EventArgs e)
{
int i = 0, j = 0, k = 0, l = 1;
if (dataGridView1[i, j].Value != "")
{
j++;
}
if (txtKodeBukuStock.Text != "" && txtJudulBukuStock.Text != "" && txtPengarangStock.Text != ""
&& txtPenerbitStock.Text != "" && txtTahunTerbitStock.Text != "" && txtJlhBukuStock.Text != "")
{
dataGridView1[k, j ].Value = txtKodeBukuStock.Text;
dataGridView1[k = k + l, j ].Value = txtJudulBukuStock.Text;
dataGridView1[k = k + l, j ].Value = txtPengarangStock.Text;
dataGridView1[k = k + l, j ].Value = txtPenerbitStock.Text;
dataGridView1[k = k + l, j ].Value = txtTahunTerbitStock.Text;
dataGridView1[k = k + l, j ].Value = txtJlhBukuStock.Text;
}
else
{
//menampilkan messageBox
MessageBox.Show("Isi textBox terlebih dahulu", "Error");
}
}

I would like to get any idea about this.. thanks

you can try following syntax for inserting data values
dataGridView1.Rows[rowIndex].Cells[columnIndex].Value = value;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.