0
我的問題是,我有一個datagridview,我添加來自數據庫的不同產品,每個產品有4個不同的價格存儲在數據庫中。 我從一個ID放在文本框中查看它們,如果ID存在,datagrid將填充它的信息。這裏的一切都很好,問題是我想要將datagridview中每個產品的所有4個價格收集到一個組合框中。我嘗試了很多,但沒有任何工作。我只能做出這樣的:把從數據庫填充的組合框放入datagridview列
'*****With this I fill a combobox*****
Dim CBdepartamento As New ComboBox
Dim Dt1 As DataTable
Dim Da1 As New SqlDataAdapter
Dim Cmd1 As New SqlCommand
'Dim dat As New DataGridViewComboBoxColumn
With Cmd1
.CommandType = CommandType.Text
.CommandText = "select precioventa from productos where idproducto =" & txtcodigo.Text + " UNION select pventa1 from productos where idproducto =" & txtcodigo.Text + " UNION select pventa2 from productos where idproducto =" & txtcodigo.Text + " UNION select pventa3 from productos where idproducto =" & txtcodigo.Text + ""
.Connection = cn
End With
Da1.SelectCommand = Cmd1
Dt1 = New DataTable
Da1.Fill(Dt1)
With CBdepartamento
.DataSource = Dt1
.DisplayMember = "precioventa"
.ValueMember = "precioventa"
End With
'*************************************
'****with this I fill the datagridview with the data obtained of the database***
Try
Dim dt As New DataTable
Using adaptador As New SqlDataAdapter("SELECT idproducto, nombre, precioventa FROM productos WHERE idproducto =" & txtcodigo.Text, cn)
adaptador.Fill(dt)
End Using
dt.Columns.Add("cantidad")
Dim cantt As Integer = 1
For Each dr As DataRow In dt.Rows
dr("cantidad") = cantt
DataGridView1.Rows.Add(dr.ItemArray)
Next
'** this "for" add the pricelist in the cbox in the column "cantidad2" with only one product is fine but if I add another, in each cbox load the four prices of the first product plus the four prices of the second one that is 8 prices in each cbox... 3 products are 12 prices in the list
For i = 0 To Dt1.Rows.Count - 1
cantidad2.Items.Add(Dt1.Rows(i).Item("precioventa"))
Next
請幫助我,它幾乎做到了我需要重複每一個產品的價格在每行的組合框
謝謝
謝謝!!現在我可以與這個工作,你給我的想法! –