lookup table using combobox

J

jaYPee

i have successfully added a combobox control in datagrid. this is the
code i have created but don't show up the record from another table.

Private Sub AddCustomDataTableStyle()

Dim ts1 As DataGridTableStyle
ts1 = New DataGridTableStyle()
ts1.MappingName = "SchYrSemCourseJoin"
' Set other properties.
ts1.AlternatingBackColor = Color.LightGray

Dim ComboTextCol As DataGridComboBoxColumn
ComboTextCol = New DataGridComboBoxColumn()
ComboTextCol.MappingName = "CourseID"
ComboTextCol.HeaderText = "Course"
ComboTextCol.Width = 100
ts1.GridColumnStyles.Add(ComboTextCol)

ts1.PreferredRowHeight =
(ComboTextCol.ColumnComboBox.Height + 3)

With ComboTextCol.ColumnComboBox
.DataSource = DsStudentCourse1
.DisplayMember = "Course.CourseID"
.ValueMember = "Course.CourseID"
End With

' c) set the dropdown style of the combo...
ComboTextCol.ColumnComboBox.DropDownStyle =
ComboBoxStyle.DropDownList
'add the custom table style to the datagrid table styles
DataGrid3.TableStyles.Add(ts1)

End Sub

i would be very glad for any reply...
 
P

Paul Clement

¤ i have successfully added a combobox control in datagrid. this is the
¤ code i have created but don't show up the record from another table.
¤
¤ Private Sub AddCustomDataTableStyle()
¤
¤ Dim ts1 As DataGridTableStyle
¤ ts1 = New DataGridTableStyle()
¤ ts1.MappingName = "SchYrSemCourseJoin"
¤ ' Set other properties.
¤ ts1.AlternatingBackColor = Color.LightGray
¤
¤ Dim ComboTextCol As DataGridComboBoxColumn
¤ ComboTextCol = New DataGridComboBoxColumn()
¤ ComboTextCol.MappingName = "CourseID"
¤ ComboTextCol.HeaderText = "Course"
¤ ComboTextCol.Width = 100
¤ ts1.GridColumnStyles.Add(ComboTextCol)
¤
¤ ts1.PreferredRowHeight =
¤ (ComboTextCol.ColumnComboBox.Height + 3)
¤
¤ With ComboTextCol.ColumnComboBox
¤ .DataSource = DsStudentCourse1
¤ .DisplayMember = "Course.CourseID"
¤ .ValueMember = "Course.CourseID"
¤ End With
¤
¤ ' c) set the dropdown style of the combo...
¤ ComboTextCol.ColumnComboBox.DropDownStyle =
¤ ComboBoxStyle.DropDownList
¤ 'add the custom table style to the datagrid table styles
¤ DataGrid3.TableStyles.Add(ts1)
¤
¤ End Sub
¤

See if the following example works for you:

Adding ComboBox to the DataGrid
http://www.visual-basic-data-mining.net/Forum/showpost.aspx?PostID=907


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
J

jaYPee

thanks for the reply but the example is the same also w/ the sample i
have downloaded from other sources. what i wanted is that the data in
the combobox that is integrated in the datagrid is come from another
table.

i have now successfully filled the data in the combobox the only
problem i have is on how to make the data in the combobox match the
data in actual table...

i have a CourseID field in my table that i want to lookup from another
table called course...the course table contains the field courseid,
course...the combobox lookups the course field from course table but
the combobox does not match the data in the actual table
 

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

Top