Updating the datasource of a "ComboBox" cell
I have a data bound grid with a column called column vendor whose data gets assigned using the following code:
Protected Function AddColumn(ByVal MapName As Object, ByVal HeaderText As String) As GridBoundColumn
Dim col As New GridBoundColumn
col.MappingName = MapName.ToString
col.HeaderText = HeaderText
Grid.GridBoundColumns.Add(col)
Return col
End Function
SIGN IN To post a reply.
5 Replies
JL
Jeff Lancaster
October 6, 2004 03:22 PM UTC
Oops, let me try this post again.
I have a data bound grid with a column called colMult whose data and styleinfo get assigned using the following code:
colMult = addColumn(fields.Multiplier, "Multiplier")
colMult.StyleInfo.CellType = "ComboBox"
colMult.StyleInfo.DropDownStyle = GridDropDownStyle.Exclusive
colMult.StyleInfo.ShowButtons = GridShowButtons.ShowCurrentCellEditing
The AddColumn function follows:
Protected Function AddColumn(ByVal MapName As Object, ByVal HeaderText As String) As GridBoundColumn
Dim col As New GridBoundColumn
col.MappingName = MapName.ToString
col.HeaderText = HeaderText
Grid.GridBoundColumns.Add(col)
Return col
End Function
So far so good. Next, I am trying to set the datasource of individuals cells in this column based on the following code:
Private Sub m_grid_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles m_grid.CurrentCellChanged
Dim Row As Integer = m_grid.CurrentCell.RowIndex
Dim Col As Integer = m_grid.CurrentCell.ColIndex
Dim MultCol As Integer
For i As Integer = 1 To m_grid.GridBoundColumns.Count
If m_grid.GridBoundColumns(i) Is colMult Then
MultCol = i + 1
Exit For
End If
Next
If m_grid.GridBoundColumns(Col - 1) Is colVendor Then
m_grid(Row, MultCol).DataSource = CLookups.VendorMultiplier(m_grid(Row, Col).CellValue)
End If
End Sub
The idea is that the combobox selections for the current row in colMult are supposed to be changed based on the selection in colVendor. I have verified the proper arraylist to which to bind the cell is being returned from CLookups, however setting the cell''s datasource does not appear to be doing anything. Any suggestions?
AD
Administrator
Syncfusion Team
October 6, 2004 03:40 PM UTC
In a GridDataBoundGrid, you cannot explicitly set specific cell style properties other than CellValue and Text (which really are the same - so you can only set one cell specific property as that is all your datasource holds).
So, if you want to specify style properties on a cell by cell basis, you have to do them dynamically, either through grid.PrepareViewStyleInfo or grid.Model.QueryCellInfo. Here is a KB discussing setting backcolor. http://www.syncfusion.com/Support/article.aspx?id=560
To set a DataSource, you would need to use model.QueryCellInfo instead of PrepareViewStyleInfo as it is hit sooner.
JL
Jeff Lancaster
October 6, 2004 04:15 PM UTC
Thanks Clay. Can you give me some direction to use model.QueryCellInfo. Do I somehow need to create a "model" for my combobox and then add a handler or something?
AD
Administrator
Syncfusion Team
October 6, 2004 04:25 PM UTC
No, you subscribe to this event using AddHandler. Here are some snippets.
''hook the handler say in FormLoad AddHandler Me.GridDataBoundGrid1.Model.QueryCellInfo, AddressOf GridQueryCellInfo ''also set the grid to refresh the whole row as the current cell changes Me.GridDataBoundGrid1.Model.Options.RefreshCurrentCellBehavior = GridRefreshCurrentCellBehavior.RefreshRow Me.GridDataBoundGrid1.Model.Options.RefreshCurrentCellBehavior = GridRefreshCurrentCellBehavior.RefreshRow ''the handler Private Sub GridQueryCellInfo(ByVal sender As Object, ByVal e As GridQueryCellInfoEventArgs) If e.ColIndex > 0 And e.RowIndex > 0 Then Dim colorRow As Boolean = False If e.ColIndex = 2 Then colorRow = (e.Style.Text = "red") Else colorRow = (Me.GridDataBoundGrid1(e.RowIndex, 2).Text = "red") End If If colorRow Then e.Style.BackColor = Color.Red End If End If End SubHere is another way you could handle this requirement. Instead of handling QCI, you could handle CurrentCellShowingDropDown. There in this event, you populate the dropdownlist at that point. At that point you can dynamically set the datasource for the list that is about to be displayed. Here is a sample
JL
Jeff Lancaster
October 6, 2004 05:15 PM UTC
Thanks again Clay. The CurrentCellShowingDropDown seemed the simplest for now and took care of my current need, and I can see where I may need to use the model.QueryCellInfo idea for some upcoming tasks. I appreciate the excellent support!
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
-
JL Jeff Lancaster
- Oct 6, 2004 03:12 PM UTC
- Oct 6, 2004 05:15 PM UTC