Input for WinForms | ComponentOne
Input Controls / DropDown
In This Topic
    In This Topic

    Input includes a powerful drop-down functionality, the DropDownControl. It provides a drop-down for any custom control. The DropDown control is a combination of a TextBox and a DropDownForm. The control's lets you look up data and select items from its list.


    The DropDownControl consists of three parts: TextBox, DropDown Button and DropDownForm.


    Add a Custom Control

    You can set a custom control that can be hosted on the DropDown control using the Control property in C1DropDownControl class.

    Let's say, you want to host a DataGridView control on the DropDown control. For this purpose, you can initialize the DropDown control, and use the Control property as shown in the code snippet below:

    Copy Code
    // Initialize DropDownControl
    C1DropDownControl dropdownControl = new C1DropDownControl();
    // Initialize DataGridView
    DataGridView dataGridView = new DataGridView ();
    // Host the DataGridView control on drop-down form.
    dropdownControl.Control = dataGridView;

    After hosting the DataGridView control on the dropdown form, the data in the cells of the grid control can be reflected in the TextBox of the Input DropDownControl using the Text property. For this purpose, you have to subscribe to the SelectionChanged event in the form.

    Copy Code
    // Subscribe to the SelectionChanged event of the DataGridView control
    dataGridView.SelectionChanged += dataGridView_SelectionChanged;

    The Text property of the DropDownControl is assigned to the Value property of the current cell in the DataGridView control using the event handler of the SelectionChanged event.

    Copy Code
    private void dataGridView_SelectionChanged(object sender, EventArgs e)
         dropdownControl.Text = dataGridView.CurrentCell.Value.ToString();

    Here, the ToString method returns the string in the current cell and displays it in the text of the TextBox of the DropDown control.