data binding Datagridcombobox column to datatable

I have a datagridview bind to datatable.
datatable structiure:
col1 nameID
col2 year

in the datagridview, I would like to add combobox from another datasource linked to the value of col1 from datatable.  Below will be the datagridview structure:
name year

how can i do that?
peterdevadossAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CodeCruiserCommented:
Can you explain in another way please. Do you mean you have a combobox fillby by using datatable and you want a value to be selected based on grid data?
0
peterdevadossAuthor Commented:
Data table:
            Dim col1 As New DataColumn()
            Dim col2 As New DataColumn()
            Col1.DataType = System.Type.GetType("System.Int32")
            Col1.ColumnName = "nameId"
            table1.Columns.Add(Col1)
            Col2.DataType = System.Type.GetType("System.String")
            Col2.ColumnName = "Locaiton"
            table1.Columns.Add(Col2)

Datagridview:
'comboboxcolumn in datagridview
            Dim typeDS As New DataSet
            sqlDa.SelectCommand = New SqlCommand("select Name,nameId from name", sqlCon)
            sqlDa.Fill(typeDS)
            Dim NameComboAs New DataGridViewComboBoxColumn
            NameComboAs .HeaderText = "Advert Type"
            NameComboAs .DataSource = typeDS.Tables(0)
            NameComboAs .DisplayMember = "AdvertType"
            NameComboAs .ValueMember = "AdvertTypeId"
            NameComboAs .ReadOnly = False

datagridview1.datasource=datatable1


- datagridview display like this: nameId,Name,location
name from combobox (bind to dataset)
nameId and location (bind to datatable)

0
CodeCruiserCommented:
Try adding this

NameComboAs.DataBindings.Add("SelectedValue", DataTable1, "NameID")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

CodeCruiserCommented:
By the way, your query is


select Name,nameId from name
but you have

NameComboAs .DisplayMember = "AdvertType"
NameComboAs .ValueMember = "AdvertTypeId"

which does not look right.
0
peterdevadossAuthor Commented:
sorry that was wrong. actually it was like this:
            NameComboAs .DisplayMember = "Name"
            NameComboAs .ValueMember = "NameId"

There is no databinding property for NameComboAs.DataBindings.

I tried like the one below, which does not work either.
NameComboAs .DataPropertyName = "AdvtType"
0
peterdevadossAuthor Commented:
Correction:
NameComboAs .DataPropertyName = "NameId"
0
peterdevadossAuthor Commented:
Sorry for wrong update:
DataPropertyName is working.
Here is the correct syntax:
NameComboAs .DataPropertyName = "NameId"
0
CodeCruiserCommented:
Good. So the problem is sorted?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.