5

VB.NET programmaticaly generating combobox in datagridview

view full story
linux-howto

http://www.daniweb.com – Hi Guys, For my application i'm trying to generate a datagridview with a comboboxcolumn in it. This combobox I wanna fill with some data from a table in my database. I've figured out how to add items to the combobox but I can't assign a value to it. The combobox is suposed to fill with product name items, and the value should be the weight of the product, so later on i can calculate the total weight. But now it's just displaying the product name, and the value is also the product name. Also I would like some sort of autonumbering in my datagrid? Anyone knows how to do this? Thanks in advance!         Dim palletds As New DataSet         Dim palletsql As String         Dim i As Integer         palletsql = "Select * from pallets"         connection = New OleDbConnection(connetionString)         Try             connection.Open()             oledbAdapter = New OleDbDataAdapter(palletsql, connection)             oledbAdapter.Fill(palletds, "pallets")             oledbAdapter.Dispose()             connection.Close()             Dim colpalsoort As New DataGridViewComboBoxColumn()             colpalsoort.DataPropertyName = "palsoort"             colpalsoort.HeaderText = "Pallet"             colpalsoort.Name = "palsoort"             colpalsoort.ReadOnly = False             colpalsoort.Visible = True             colpalsoort.Width = 85             For i = 0 To palletds.Tables(0).Rows.Count - 1                 colpalsoort.Items.Add(palletds.Tables(0).Rows(i).Item("pallet_type"))             Next           DataGridView1.Columns.Add(colpalsoort)         Catch ex As Exception             MsgBox("Can not open connection ! ")         End Try (General)