Monday, February 9, 2015

How to prevent selection change in drop down from key press when UltraComboEditor’s DropdownStyle set to DropDownList?

Scenario: Current requirement is that user can select option from drop down from mouse selection only, but whenever use type anything in the drop down it automatically raise control’s ComboBox.SelectionChangeCommitted event with first match that satisfies auto complete condition of the control. As required we need ignore the key press to raise the ComboBox.SelectionChangeCommitted event of the combo box and it only allow selection only on mouse.

Solution:
To do this, I set the control’s DropdownStyle set to DropDownList, but no work correctly. Along this I have to suppress combo box’s key press by handling KeyDown event as below.

LibraryListDropdown libDropdown = null;
public Form1()
{
    InitializeComponent();
    libDropdown = new LibraryListDropdown();
    this.libDropdown.DropDownStyle = DropDownStyle.DropDownList;
    libDropdown.Name = "cmbObjectType";
    libDropdown.SelectionChangeCommitted += new EventHandler(libDropdown_SelectionChangeCommitted);
    libDropdown.KeyDown += libDropdown_KeyDown;
    this.Controls.Add(libDropdown);
    libDropdown.PopulateLibraries();
}

void libDropdown_KeyDown(object sender, KeyEventArgs e)
{
    e.SuppressKeyPress = true;
}

private void libDropdown_SelectionChangeCommitted(object sender, EventArgs e)
{
    
}

No comments :

Post a Comment