0

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

2
Contributors
2
Replies
5
Views
7 Years
Discussion Span
Last Post by babbu
0

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
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.