Xceed Grid for WinForms v4.3 Documentation
DropDown control

Welcome to Xceed Grid for WinForms v4.3 > Basic Concepts > Editor Controls > WinTextBox control > DropDown control

The DropDownControl property of the WinTextBox control allows any control to be assigned as its dropdown. The dropdown can be opened either by using the   OpenDropDown method, by setting the DroppedDown property to true, or by clicking on the WinButton control assigned to its DropDownButton property. To close the dropdown, the CloseDropDown method can be called, the DroppedDown property set to false, or the DropDownButton clicked (if the dropdown is currently open). 

For example, in the image and code below, a rough version of the WinDatePicker control was recreated by assigning a WinCalendar control as the WinTextBox control's DropDownControl. In this case, the dropdown will be opened by the DropDownButton. 

See example

VB.NET
Copy Code
Dim textBox As New WinTextBox

Dim dropButton As New WinButton

dropButton.ButtonType = New ButtonType( ButtonBackgroundImageType.Combo, _

                                        ButtonImageType.ScrollDown )

dropButton.Width = 18

textBox.SideButtons.Add( dropButton )

Dim dropDown As New WinCalendar

dropDown.MaxValue = DateTime.Today.AddMonths( 12 )

' Keep a reference to our parent WinTextBox control using the Tag property so that we can

' set its Text property in the SelectedDateChanged event when a new date is selected.

'

' Another option would have been to declare the parent WinTextBox control globally rather

' than locally.

dropDown.Tag = textBox

AddHandler dropDown.SelectedDateChanged, AddressOf Me.DateSelected

textBox.DropDownControl = dropDown

textBox.DropDownButton = dropButton

textBox.TextBoxArea.Text = DateTime.Today.ToLongDateString()

textBox.Location = New Point( 10, 10 )

Me.Controls.Add( textBox )

Private Sub DateSelected( ByVal sender As Object, ByVal e As SelectedDateChangedEventArgs )

  Dim calendar As WinCalendar = CType( sender, WinCalendar )

  Dim textBox As WinTextBox = CType( calendar.Tag, WinTextBox )

  textBox.TextBoxArea.Text = calendar.SelectedDate.ToLongDateString()

End Sub
C#
Copy Code
WinTextBox textBox = new WinTextBox();

WinButton dropButton = new WinButton();

dropButton.ButtonType = new ButtonType( ButtonBackgroundImageType.Combo,

                                        ButtonImageType.ScrollDown );

dropButton.Width = 18;

textBox.SideButtons.Add( dropButton );

WinCalendar dropDown = new WinCalendar();

dropDown.MaxValue = DateTime.Today.AddMonths( 12 );

// Keep a reference to our parent WinTextBox control using the Tag property so that we can

// set its Text property in the SelectedDateChanged event when a new date is selected.

//

// Another option would have been to declare the parent WinTextBox control globally rather

// than locally.

dropDown.Tag = textBox;

dropDown.SelectedDateChanged = new SelectedDateChnagedEventHandler( this.DateSelected );

textBox.DropDownControl = dropDown;

textBox.DropDownButton = dropButton;

textBox.TextBoxArea.Text = DateTime.Today.ToLongDateString();

textBox.Location = new Point( 10, 10 );

this.Controls.Add( textBox );

private void DateSelected( object sender, SelectedDateChangedEventArgs e )

{

  WinCalendar calendar = ( WinCalender )sender;

  WinTextBox textBox = ( WinTextBox )calender.Tag;

  textbox.TextBoxArea.Text =   calendar.SelectedDate.ToLongDateString();

}

Dropdown direction

The direction in which the dropdown is opened depends on the value of the DropDownDirection property. If set to Automatic (default), the dropdown will open below the control if enough space is available. If there is not enough space below the control, the dropdown will open above it. If the DropDownDirection property is set to Up, the dropdown will open above the control. If set to Down, the dropdown will open below the control. 

The dropdown's anchor point is determined by the DropDownAnchor property (by default DropDownAnchor.Left). The position of the dropdown's resizing grip will be at the opposite of the dropdown's anchor point. For example, in the first image, the DropDownAnchor property is set to DropDownAnchor.Left, and its resizing grip is located on the right. In the second image, the DropDownAnchor property is set to DropDownAnchor.Right; therefore, the resizing grip is located on the left. 

Allowing focus

The DropDownAllowFocus property of the WinTextBox control determines if the control assigned to the DropDownControl property can receive focus. If the DropDownAllowFocus property is set to false (default), the dropdown will close as soon as the mouse clicks in the dropdown, thus preventing navigation or operations within the dropdown. If set to true, the dropdown will remain open until the WinTextBox control's CloseDropDown method is called, the DroppedDown property set to false, or the DropDownButton is pressed.