Home Forums WinForms controls Xceed Grid for WinForms Property grid with drop down combobox – detect value changed?

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16485 |

    I’ve got a GridControl which I’m using as a property grid with a CellEditorManager etc.  One of the property rows is a WinComboBox type, and when the value changes by selection the SelectedItemChanged event is handled.  This is all fine.

    However, I want to detect that a value has changed from outside this combo box, so that I can update other controls on my main form.  To do this I handle the CellEditorManager.GettingControlValue event, but this only happens when the property cell loses focus (click on another cell/row or control).

    This is too late for me, I need my main form to notice when drop down selected index has changed.

    I tried invalidating the WinComboBox, programatically losing the focus, redraw etc., but all of these things happen in context of the WinComboBox only, not in the wider context of the property grid control.

    Any ideas?

    Cheers,

    Boz

    Imported from legacy forums. Posted by James (had 2358 views)

    User (Old forums)
    Member
    Post count: 23064

    You need to subscribe to 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 void Form1_Load(object sender, System.EventArgs e)
        {
          gridControl1.Columns[ “column6” ].CellEditorManager.ActivatingControl += new CellEditorEventHandler(CellEditorColumn6_ActivatingControl);
          gridControl1.Columns[ “column6” ].CellEditorManager.DeactivatingControl += new CellEditorEventHandler(CellEditorColumn6_DeactivatingControl);
        }

    //Event handlers

        private void CellEditorColumn6_ActivatingControl(object sender, CellEditorEventArgs e)
        {
          ( ( WinComboBox )e.Control).SelectedIndexChanged += new EventHandler(ComboBoxColumn6_SelectedIndexChanged);
        }

        private void CellEditorColumn6_DeactivatingControl(object sender, CellEditorEventArgs e)
        {
          //need to unsubscribe to the event, so it does not keep piling up in the ActivatingControl
          ( ( WinComboBox )e.Control).SelectedIndexChanged -= new EventHandler(ComboBoxColumn6_SelectedIndexChanged);
        }

        private void ComboBoxColumn6_SelectedIndexChanged(object sender, EventArgs e)
        {
          string index = “index ” + ( ( WinComboBox )sender).SelectedIndex.ToString();
          System.Diagnostics.Debug.WriteLine( index );
        }

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

    User (Old forums)
    Member
    Post count: 23064

    Thanks for the reply.  I subscribed to ActivatingControl and DeactivatingControl, but they only fire when the ComboBox becomes active and deactive.  What happens is the user clicks the drop down button, first the SettingControlValue and ActivatingControl events fire, then the list of items in the ComboBox appears, the user chooses an item in the list, the list hides and the text box portion of the control shows the text of the selected item, but no other events have fired.  When the user moves focus away from that ComboBox, then the DeactivatingControl and GettingControlValue fire, but that’s too late for me.

    For example of the behaviour I need, look at Visual Studio’s Properties window.  Add a control to a form in the form designer, then in the Properties window click the drop down button on the Dock property, then choose one of the dock options and you’ll see the effect of that selection is immediate on the control.  You don’t have to move focus from the property.

    Thanks

    Boz

    Imported from legacy forums. Posted by James (had 445 views)

    User (Old forums)
    Member
    Post count: 23064

    Sorry to push you, but any chance of a response before the weekend, even if it’s just to say you’re working on it.

    Much appreciated

    Boz

    Imported from legacy forums. Posted by James (had 335 views)

    User (Old forums)
    Member
    Post count: 23064

    In the ActivatingControl event handler, do you subscribe to the SelectedIndexChanged event of the WinComboBox?  If so, this event should be fired every time the selection changes in the ComboBox, without it having to loose focus.

    If this is not the behavior you are seeing in the grid, then I suspect an exception is thrown somewhere in the event handlers, but you don’t see it because it is swallowed by the grid or the .NET framework.

    To trap exceptions, you need to set the debugger to break on all exception.  Go to Debug Menu -> Exceptions -> Common Language Runtime Exceptions.  Select “Break into the debugger” radio button in VS2003, or select “Thrown” CheckBox in VS2005/2008.

    If you are in VS2005/2008, make sure the “Enable Just My Code” CheckBox is unselected (Tools Menu -> Options -> Debugging -> General).

    This will make sure that no exceptions are swallowed by the grid or the framework, and that the debugger will break in any part of the code, not just yours.

     

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

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.