this is my code

dataGridView1.Rows.Add()
            dataGridView1.Item(0, dataGridView1.Rows.Count - 1).Value = cboColourCode.SelectedText.ToString
            dataGridView1.Item(0, dataGridView1.Rows.Count - 1).Value = txtQty.Text.Trim.ToString
            dataGridView1.Item(0, dataGridView1.Rows.Count - 1).Value = cboQty.SelectedText.ToString

only a blank row is added in the datagrid

Recommended Answers

All 2 Replies

Try this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim idx As Integer = DataGridView1.Rows.Add()
		DataGridView1.Rows(idx).Cells(0).Value = "Abc"
		DataGridView1.Rows(idx).Cells(1).Value = "123"
		DataGridView1.Rows(idx).Cells(2).Value = "456"
	End Sub

my previous code is working fine. i had made a few mistakes.

dataGridView1.Rows.Add()
            dataGridView1.Item(0, dataGridView1.Rows.Count - 1).Value = cboColourCode.SelectedItem.ToString
            dataGridView1.Item(1, dataGridView1.Rows.Count - 1).Value = txtQty.Text.Trim.ToString
            dataGridView1.Item(2, dataGridView1.Rows.Count - 1).Value = cboQty.SelectedItem.ToString

i forgot to change the column index and the selected item property of the combo box was supposed to be used
thnx ne ways

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.