0

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

3
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by Mitja Bonca
0

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

0

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.

0

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

0

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

0

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.

0

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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.