Home Forums WinForms controls Xceed Grid for WinForms Update CellEditorManager on runtime Reply To: Update CellEditorManager on runtime

User (Old forums)
Member
Post count: 23064

When assigning an editor to a CellEditorManager, you are setting a template which will be used when a cell of that column is entering edition.  Once this template is assigned to a CellEditorManager, any update to this template will not be taken into account by the grid.  This is why you need to update the live instance, and not the template, of the editor, as the cell enters edition.

So to do this, you need to subscribe to the ComboBox events through the ActivatingControl event of the CellEditorManager.  This is necessary because the editor is actually initialized only when the cell receives focus, and enters the edit mode.

e.g.:

//at Form_Load

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    AddHandler GridControl1.Columns( 0 ).CellEditorManager.ActivatingControl, AddressOf CheckBoxEditor_ActivatingControl
    AddHandler GridControl1.Columns( 0 ).CellEditorManager.DeactivatingControl, AddressOf CheckBoxEditor_DeactivatingControl

  End Sub

//Event handlers

  Private Sub CellEditorManager_ActivatingControl( ByVal sender As Object, ByVal e As Xceed.Grid.Editors.CellEditorEventArgs )

    Dim editor as Xceed.Editors.WinComboBox = CType( e.Control, Xceed.Editors.WinComboBox )
    ‘Here you can add or remove items instead of (or in addition to) subscribing to events.
    editor.Items.add(…)
    AddHandler editor.SelectedIndexChanged, AddressOf editor_SelectedIndexChanged

  End Sub

  Private Sub CellEditorManager_DeactivatingControl( ByVal sender As Object, ByVal e As Xceed.Grid.Editors.CellEditorEventArgs )
   
    Dim editor as Xceed.Editors.WinComboBox = CType( e.Control, Xceed.Editors.WinComboBox )
    ‘this needs to be done, if not, subscriptions will pill up every time the editor is activated
    RemoveHandler editor.SelectedIndexChanged, AddressOf editor_SelectedIndexChanged
 
  End Sub

  Private sub editor_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As EventArgs )

    Dim index As String = “index ” + CType( sender, WinComboBox ).SelectedIndex.ToString()
    System.Diagnostics.Debug.WriteLine( index )
   
  End Sub

Imported from legacy forums. Posted by André (had 1161 views)