ComboBox DropDownClosed event?


https://www.nevron.com/Forum/Topic12206.aspx
Print Topic | Close Window

By Damien Drummond - 7 Years Ago
I am testing your controls and I am using your combobox. Now if a user clicks on it and selects an item (where the item selected is different) then I can use your SelectedIndexChanged event to do something (in my case move focus back to another control). However, if they don't select a different item and the combobox closes what event is fired that I can use - nothing I can see from the little information I have?

With the standard combobox I had one event DropDownClosed and it handled the event whether a different item was selected or not.

Why do your controls lack the standard (essential) events that I should be able to use?

Also, since your documentation covers nothing relating to creating a style/theme for a ComboBox (or anything other than a button), how do I go about setting a default style for my ComboBox and is it possible to have two themes, and changing them depending what section of my application the user is in at time?

Thanks in advance.

D








By Nevron Support - 7 Years Ago
Hi,

All controls that host a popup window in NOV (including the combo box) have a Popup property that represents the popup window shown by the control. In the case of drop down controls like the combo box this is the popup window that is shown when you click the drop down arrow button of the control. You can subscribe to the Closed event of this popup window to get notified when it gets closed like shown in the following example:

comboBox.Popup.Closed += OnComboBoxPopupClosed;

private void OnComboBoxPopupClosed(NEventArgs arg)
{
  // Your code here
}


Regarding the UI themes, you can change the appearance of a combo box similarly to a button. You have to create the proper CSS selector that selects either the combo box or the part of it which appearance you want to change in your theme and then add the style definitions you want to apply. We have sent you the source code related to NOV UI themes, as well as a sample application that demonstrates how to create a custom theme based on the built-in Windows 8 theme via email.

By Damien Drummond - 7 Years Ago
Okay, that makes sense, but I can't find that on my system.

So where do I put the "comboBox.Popup.Closed += OnComboBoxPopupClosed;" I assume it is in the initialization function, but I would have thought that this would also have shown under the properties section, which if it had, I may have been able to identify it sooner.

All I get is an error no matter where it is placed...

SeverityCodeDescriptionProjectFileLineSuppression State
ErrorCS1061'NComboBoxControl' does not contain a definition for 'Popup' and no extension method 'Popup' accepting a first argument of type 'NComboBoxControl' could be found (are you missing a using directive or an assembly reference?)usePacketC:\Users\dpd\source\repos\usePacket\usePacket\Form1.Designer.cs89Active


Am I missing something?

The following references are already added to my project (which I started fresh as a NOV WinForms application...
Nevron.Nov.Barcode
Nevron.Nov.Chart
Nevron.Nov.Diagram
Nevron.Nov.Grid
Nevron.Nov.Host.WinBase
Nevron.Nov.Host.WinForm
Nevron.Nov.Presentation
Nevron.Nov.Schedule
Nevron.Nov.Text
Nevron.Nov.WinFormControls

I also am not receiving any email notification when you respond, even though I have it set to "Subscribe by Email".

Thanks.


By Damien Drummond - 7 Years Ago
I don't get an error if I use the following, but it also doesn't fire...

combobox.Widget.Popup.Closed += OnComboBoxPopupClosed;

I find I have to use the "Widget" part in quite a lot of the coding, so is something not right? I have removed and reinstalled your application, but it didn't change anything.

I am using Visual Studio Professional 2017 v15.3.5 if that helps? Also coding for NET Framework 4.5.2 if that also adds anything to this?

thanks.

By Nevron Support - 7 Years Ago
Hi,

If you are using the NOV controls from the toolbox, then yes, you will have to use the Widget property of each control to access the NOV widget hosted in it. Please note that if you use controls from the toolbox you are sacrificing the portability of your code, which is one of the greatest powers of NOV. If you code your application directly by using NOV widgets instead of WinForm controls via the Visual Studio designer you will be able to compile and run your application on all platforms supported by NOV (currently Windows (WinForms and WPF), Mac and Silverlight) from a single codebase.

The following is a simple example that shows how to create some NOV widgets directly in code without using the Visual Studio designer - the NOV UI is created in the CreateNovContent method:
public partial class Form1 : Form
  {
   public Form1()
   {
      InitializeComponent();

      // Create the NOV content and place it in a NOV widget host on the form
      NWidget novContent = CreateNovContent();
      NNovWidgetHost<NWidget> host = new NNovWidgetHost<NWidget>(novContent);
      host.Dock = DockStyle.Fill;
      Controls.Add(host);
   }

   private NWidget CreateNovContent()
   {
      NStackPanel stack = new NStackPanel();
      stack.Padding = new NMargins(NDesignConstants.HorizontalSpacing, NDesignConstants.VerticalSpacing);
      stack.VerticalSpacing = NDesignConstants.VerticalSpacing;

      // Create a button
      NButton button = new NButton("Button");
      stack.Add(button);

      // Create a button with image and text
      NButton imageButton = NButton.CreateImageAndText(Nevron.Nov.Presentation.NResources.Image_File_Open_png, "Open");
      stack.Add(imageButton);

      // Create a check box
      stack.Add(new NCheckBox("Check Box"));

      return stack;
   }
  }


For more information on hosting NOV in a Windows Forms application, you can check out the Hosting NOV in Windows Forms documentation topic.
By Damien Drummond - 7 Years Ago
Does this then sacrifice the ability for me to view the item in the designer?

I like to get the layout right visually before adding the code behind it?

Thanks.
By Damien Drummond - 7 Years Ago
So changing to this (for testing)...
private void OnComboBoxPopupClosed(NEventArgs arg)
   {
    MessageBox.Show("test");
    scannedItems.Focus();
   }


The message box shows, so it is firing, what it is not doing is performing the focus to the datagridview.

If I have this, it fires and sets focus correctly, but only if I change the selection...
  private void nComboBoxControl2_SelectedIndexChanged(NValueChangeEventArgs arg)
   {
    scannedItems.Focus();
   }


Can you explain where I am going wrong? To be honest, it should not be this hard Sad.

thanks.

By Nevron Support - 7 Years Ago
When the drop down popup of the NOV combo box closes it automatically sets focus back to the combo box. That is why your code is not working as expected - you set the focus to the data grid view in the Closed event but shortly after that the popup sets its back to the NOV combo box. A solution to this problem is to use a timer to focus the data grid view some time after the combo box drop down popup has closed (for example 0.1 sec after that) like show in the following piece of code:
comboBox.Popup.Closed += OnComboBoxDropDownPopupClosed;

private void OnComboBoxDropDownPopupClosed(NEventArgs arg)
{
  NTimer timer = new NTimer(100);
  timer.Tick += delegate() {
   timer.Stop();
   dataGridView1.Focus();
  };

  timer.Start();
}