We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Updating the datasource of a "ComboBox" cell

Thread ID:

Created:

Updated:

Platform:

Replies:

19929 Oct 6,2004 03:12 PM UTC Oct 6,2004 05:15 PM UTC WinForms 5
loading
Tags: GridControl
Jeff Lancaster
Asked On October 6, 2004 03:12 PM UTC

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

Jeff Lancaster
Replied On 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?

Administrator [Syncfusion]
Replied On 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.

Jeff Lancaster
Replied On 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?

Administrator [Syncfusion]
Replied On 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 Sub
Here 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

Jeff Lancaster
Replied On 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!

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;