Hi every one! I would like to know if it's possible to have differents items in a combo box in each row. It there is way. Please help!!! Thanks

Recommended Answers

All 7 Replies

your already placing the combo on grid and you want to know how to bind records to that combo?

Hi Pgmer. I already put the combo on the grid and I am able able to insert content.
Let me try to make it clear.
I want the items in a combo box to change depending on another column selection
E.g. I have two columns :1. Fabric name and 2. Color
Color is a combobox column type.
When you select a fabric name, I want the colors available for that fabric to be displayed in the corresponding combo box for that specific row.
Hope it's clear now.

ok then what you need to do is, in the selected index changed event of Fabric combo you need to filter the records of colr combo.
Get the datasource what u attched to color combo to dataview and use rowfilter on fabric change, and assign that dataview as source to colr combo. hope you get idea

Thanks for your reply but I am still not getting the point. Would you mind make it more clear? Thanks

Can you show your code which ur using to bind the records to combo in grid?

Hi every one! I would like to know if it's possible to have differents items in a combo box in each row. It there is way. Please help!!! Thanks

Hi, you will have to do a loop through all the rows of datagrid and based on othe column set the comboboxcell for each cell.

I did a simple example (in a few minutes) to show you how can be done:

Private dgv As DataGridView
Public Sub New()
	InitializeComponent()
	'creating and adding columns to dgv:
	dgv = New DataGridView()
	Me.Controls.Add(dgv)
	Dim combo As New DataGridViewComboBoxColumn()
	If True Then
		combo.Name = "c2"
		combo.HeaderText = "column 2"
	End If
	dgv.Columns.Add("c1", "column 1")
	dgv.Columns.Insert(1, combo)

	'adding some example rows:
	For i As Integer = 1 To 4
		dgv.Rows.Add(i, Nothing)
	Next
	' adding data into 1st column, int 2nd (combo) nothing
	' and based on this column, will we now add data to comboboxcell:
	For Each row As DataGridViewRow In dgv.Rows
		Dim cell As New DataGridViewComboBoxCell()
		Dim dataToUse As Integer = Convert.ToInt32(row.Cells(0).Value)
		cell.DataSource = SetComboBoxCell(dataToUse)
		dgv(1, row.Index) = cell
	Next
End Sub

Private Function SetComboBoxCell(i As Integer) As List(Of String)
	Dim list As New List(Of String)()
	Select Case i
		Case 1
			list.AddRange(New String() {"A1", "B1", "C1"})
			Exit Select
		Case 2
			list.AddRange(New String() {"A2", "B2", "C2"})
			Exit Select
		Case 3
			list.AddRange(New String() {"A3", "B3", "C3"})
			Exit Select
		Case 4
			list.AddRange(New String() {"A4", "B4", "C4"})
			Exit Select
	End Select
	Return list
End Function
Convert again
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.