Datagridview with Combobox



Using VB.Net 2008

I have this code in a form, to create the cells on my datagridview.
Depending on the users selection, the grid is created.

This sample is for the Creditors.

The following works and populates the combo box, and the text boxes.
Need to find the ID value to enter it in the txtgrFixedID field once an
is selected.

With frmMain.grdSelections


'The commented code works to add a combo to the grid.

Dim txtgrFixedID As New DataGridViewTextBoxColumn

Dim colgrExpress As New DataGridViewComboBoxColumn

Dim txtgrMnthly As New DataGridViewTextBoxColumn

Dim txtgrYearly As New DataGridViewTextBoxColumn

txtgrFixedID.Name = "AssetsID"

With colgrExpress

'.Name = "Select a Variable Expense"

..HeaderText = "Select an Asset"

..ReadOnly = False

..AutoComplete = True

..DropDownWidth = 250

End With

With txtgrMnthly

..Name = "Value of Asset"

..DefaultCellStyle.NullValue = FormatNumber("0.00")

..ReadOnly = False

End With

With txtgrYearly

..Name = "Maturity Date"

..DefaultCellStyle.NullValue = Format(Now(), "MMM dd, yyyy")

..ReadOnly = True

End With

'Open the connection.


Dim rea As OleDbDataReader

Dim cmd As New OleDb.OleDbCommand("SELECT * FROM AssetsItems", con)

rea = cmd.ExecuteReader


'Load the DataGridView.

While rea.Read()


colgrExpress.DisplayMember = "NAssets"

colgrExpress.ValueMember = "AssetsID"

End While

'Close the connection.






..Columns(0).Width = 0

..Columns(1).Width = 150

..Columns(2).Width = 100


I was able to use the ItemData in VB6.

I need to be able to fnd the AssetsID when user selects a value from the
combo box.

Any tips on how to get this.

Was so easy in VB6

Cor Ligthert


I had the problem that I found it so difficult in VB6.

But as I see your code you make it in my idea senseless dificult.
A simple datatable or dataset with tableadapter or dataadapter should be
Don't assume that your program becomes quicker by writting more rows of code
your own.


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Datagridview 1