Question DataGridView ComboBoxColumn, how to display different values per row

seraphim04

Member
Joined
Oct 30, 2013
Messages
8
Programming Experience
1-3
aaa.png

Those are 2 Rows on a DataGridView
under the same ComboBoxColumn.
The DropDown Values are different from each other
any idea how to do that?
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,553
Location
Sydney, Australia
Programming Experience
10+
Normally, you set the DataSource property of the column and that gets automatically propagated to the DataSource property of each cell and that gets automatically propagated to the DataSource of the editing control. If you want each cell to have a different data source then that's exactly what you do: don't set the DataSource of the column but rather set the DataSource of each cell individually.
 

seraphim04

Member
Joined
Oct 30, 2013
Messages
8
Programming Experience
1-3
Normally, you set the DataSource property of the column and that gets automatically propagated to the DataSource property of each cell and that gets automatically propagated to the DataSource of the editing control. If you want each cell to have a different data source then that's exactly what you do: don't set the DataSource of the column but rather set the DataSource of each cell individually.

can somehow show me what to do it?
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,553
Location
Sydney, Australia
Programming Experience
10+
The properties are exactly the same as they are for a regular ComboBox so you set them just like you would for a regular ComboBox. The real question is WHEN to set them. Obviously they have to be set when some event is raised because that's how event-driven technologies like Windows Forms work. It's for you to determine exactly when it is that you know what values you want to include for a particular cell and what event is raised at that moment. Will the list be decided by a value being set in another cell in the same row? Then it's the CellValueChanged event you want. Etc.
 

seraphim04

Member
Joined
Oct 30, 2013
Messages
8
Programming Experience
1-3
well i know how to set the property but, the one i can set is for the whole column instead of for just one cell..

can give me an example how to set datasource for each cell instead of the whole column
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,553
Location
Sydney, Australia
Programming Experience
10+
You're trying to make this hard when it's not.
myCell.DataSource = dataSource
Exactly as you'd expect.
 

seraphim04

Member
Joined
Oct 30, 2013
Messages
8
Programming Experience
1-3
i was trying to get an answer similar to this one...

Probe.SelectCommand.CommandText = "(SELECT InvSys_ItmSrv_Units.Unit FROM InvSys_ItmSrv_Items LEFT JOIN InvSys_ItmSrv_Units ON InvSys_ItmSrv_Items.Unit=PK_ItemUnits WHERE PK_ItemsCode='" & dtgrid2.Rows(i).Cells(0).Value & "') UNION ALL (SELECT InvSys_ItmSrv_Units.Unit FROM InvSys_ItmSrv_Items LEFT JOIN InvSys_ItmSrv_Units ON BigUnit=PK_ItemUnits WHERE PK_ItemsCode='" & dtgrid2.Rows(i).Cells(0).Value & "')"
Probe.Fill(ds, "Unit")
Dim cell As New DataGridViewComboBoxCell
cell = PODtls.dtgrid.Rows(PODtls.dtgrid.Rows.Count - 1).Cells(4)
cell.DataSource = (ds.Tables("Unit"))
cell.DisplayMember = "Unit"
cell.Value = CType(cell.Items(cell.Items.Count - 1), DataRowView).Row(0)
Probe.Dispose()
ds.Dispose()
===========================

this was the part I was looking for the one in bold text
cause having only the cell.DataSource = (ds.Tables("Unit"))
won't be a solution to the question since the problem is how to set it per cell, not just how to set a datasource
i'm not trying to make it hard, since I never have tried it before, and because I was used to only setting datasource to the whole combobox column.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,553
Location
Sydney, Australia
Programming Experience
10+
That code is setting the DataSource of a cell so that's exactly what to do. The issue is that you're just creating a cell out of thin air and setting the DataSource of that, which is useless. If you want to affect the cells in the grid then you have to set the DataSource of the cells in the grid, not some other cell that you just created. If you expect more specific information then maybe you should address the point I raised in post #4. I didn't do so for my health.
 
Top Bottom