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

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

dear fellow member:

all I can say is that controls such as comboboxes and listboxes and textboxes can only bind to JUST ONE FIELD OF THE TABLE.
YOU SHOULD USE ANOTHER COMBOBOX OR LISTBOX FOR DISPLAYING THE VALUE.
try to use the binding class... if necessary

As for the autonumbering you can use this code if u find it useful:
One way to do this by using a new SQL Server 2005 function Row_Number() OVER:

If you are using SQL Server 2005, you can do something linke this:

In youe select statement:

SelectCommand="SELECT Row_Number() OVER(order by id) as rowID, [mycol1], [mycol2], [id] FROM [Table1]"

In you GridView:

<asp:BoundField DataField="Rowid" HeaderText="Rowid" ReadOnly="True" SortExpression="Rowid" />

You are ready to go.

Thanks guys for thinking along!

About the auto number, i don't use sql but an access mdb...

About the combobox: Filling it with the items is working fine, but what I need is this

The combobox needs to display the product name. Then you can select the product name in the combobox. Then you fill in some other info in the row in the datagrid. When you leave the row an information label needs to be printed. On that information label I need to display the weight of the product selected.

I know this can be done because when you use the GUI to create a grid with a combobox and the databinding then it works.

I think it has something to do with displaymember and valuemember but i can't figure it out.....

Anyone??

This is the same idea but HTML, i need it in VB.NET for a winform.

<select name="menu" size="3" multiple>

        <option value="1">maple</option>

        <option value="2">hickory</option>

        <option value="3">birch</option>

    </select>

Okay i figured out the combobox thing....
Now i still need to figure out the autonumbering!

This article has been dead for over six months. Start a new discussion instead.