Event Handling in Windows Forms xp toolbar

10 Oct 20227 minutes to read

Selection Events

The events present in the Combobox can be applied for ComboBoxAdv control. 

ComboBoxAdv Events Description
SelectedIndexChanged Handled when SelectedIndex property is changed.
SelectedIndexChanging Handled when SelectedIndex property is changing.
SelectedValueChanged Handled when SelectedValue property is changed.
SelectionChangeCommitted Handled when the user selects a new text for the combo.
DropDown Event Handled before the dropdown is shown.

The ComboBoxAdv handles different events for the different user interaction scenarios. The occurrence and order of the events are tabulated as follows. 

Scenarios SelectionChangedCommitted Event SelectedValueChanged SelectedIndexChanged Validating/Validated
TextArea-Change Selection by Keys Yes:1 Yes:2 Yes:3 No
TextArea-On AutoComplete No No No No
Drop-Down List-Change Selection by Keys No Yes:1 Yes:2 No
Drop-Down List-Change Selection by Mouse Move No No No No
Drop-Down Close by Enter Key Yes:1 No No No
Drop-Down Close by Escape Key No No No No
Drop-Down Close by clicking Yes:1 Yes:2 Yes:3 No
Losing Focus Yes:2 (in DropDownStyle.DropDown (editable) mode only) No No Yes:1
Changing Text Property in Code Yes:1 No No No

Populating the ComboBoxAdv

To populate the ComboBoxAdv containing the predefined percent values with other percent values and allowing the text field of the ComboBoxAdv to behave like PercentTextBox, follow the given steps:

  • Derive a new class from the existing Syncfusion ComboBoxAdv. Override as shown here and give a new definition for TextBox.

// Derive a new class from the existing Syncfusion ComboBoxAdv.
   public class PercentComboBoxAdv : Syncfusion.Windows.Forms.Tools.ComboBoxAdv
   {
   // Overrides the internal TextBox.
   	protected override TextBox CreateTextBox()
   	{
       	Syncfusion.Windows.Forms.Tools.PercentTextBox  ptb = new Syncfusion.Windows.Forms.Tools.PercentTextBox ();
   
   		return ptb as TextBox;
   
   	}
   
   	public new Syncfusion.Windows.Forms.Tools.PercentTextBox TextBox
   
   	{
   
   		get
       	{
   
   	    	return (Syncfusion.Windows.Forms.Tools.PercentTextBox ) base.TextBox;
   
   		}
   	}
   }
' Derive a new class from the existing Syncfusion ComboBoxAdv.
   Public Class PercentComboBoxAdv : Inherits Syncfusion.Windows.Forms.Tools.ComboBoxAdv
   ' Overrides the internal TextBox.
   Protected Overrides Function CreateTextBox() As TextBox
   Dim ptb As Syncfusion.Windows.Forms.Tools.PercentTextBox = New Syncfusion.Windows.Forms.Tools.PercentTextBox ()
   Return CType(IIf(TypeOf ptb Is TextBox, ptb, Nothing), TextBox)
   End Function
   Public Shadows ReadOnly Property TextBox() As Syncfusion.Windows.Forms.Tools.PercentTextBox
   Get
   Return CType(MyBase.TextBox, Syncfusion.Windows.Forms.Tools.PercentTextBox)
   End Get
   End Property
   End Class
  • Create an instance for the derived class and initialize.

// Do the initialization.
   private PercentComboBoxAdv PercentComboBoxAdv1;
   this.PercentComboBoxAdv1 = new PercentComboBoxAdv();
   this.PercentComboBoxAdv1.Location = new System.Drawing.Point(this.Width/4, this.Height/3);
   this.Controls.Add(this.PercentComboBoxAdv1);
   this.PercentComboBoxAdv1 .SelectedValueChanged+= newSystem.EventHandler(this.PercentComboBoxAdv1_SelectedValueChanged);
'Do the initialization.
   Private PercentComboBoxAdv1 As PercentComboBoxAdv
   Me.PercentComboBoxAdv1 = New PercentComboBoxAdv()
   Me.PercentComboBoxAdv1.Location = New System.Drawing.Point(Me.Width/4, Me.Height/3)
   Me.Controls.Add(Me.PercentComboBoxAdv1)
   Me.PercentComboBoxAdv1.SelectedValueChanged+= NewSystem.EventHandler(Me.PercentComboBoxAdv1_SelectedValueChanged)
  • You can populate the derived control with values using Items property.

private void Form1_Load(object sender, System.EventArgs e)
   {
   // Populating the control with items.
   this.PercentComboBoxAdv1.Items.Add (78.9);
   this.PercentComboBoxAdv1.Items.Add (67.9);
   this.PercentComboBoxAdv1.Items.Add (75.9);
   this.PercentComboBoxAdv1.Items.Add (23.6);
   this.PercentComboBoxAdv1.Items.Add (34.7);
   this.PercentComboBoxAdv1.Items.Add (56.8);
   }
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
   
   'Populating the control with items.
   Me.PercentComboBoxAdv1.Items.Add (78.9)
   Me.PercentComboBoxAdv1.Items.Add (67.9)
   Me.PercentComboBoxAdv1.Items.Add (75.9)
   Me.PercentComboBoxAdv1.Items.Add (23.6)
   Me.PercentComboBoxAdv1.Items.Add (34.7)
   Me.PercentComboBoxAdv1.Items.Add (56.8)
   End Sub
  • In the SelectedValueChanged event, you can display the corresponding selected value in Percent Format.

private void PercentComboBoxAdv1_SelectedValueChanged(object sender, System.EventArgs e)
   { 
   // Displays the corresponding selected value.
       this.PercentComboBoxAdv1.TextBox.PercentValue = Double.Parse (this.PercentComboBoxAdv1.SelectedItem.ToString());
   }
Private Sub PercentComboBoxAdv1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs)
   
   ' Displays the  corresponding selected value.
   Me.PercentComboBoxAdv1.TextBox.PercentValue = Double.Parse (Me.PercentComboBoxAdv1.SelectedItem.ToString())
   End Sub

Overview_img313