ComponentOne True DBGrid for WinForms
True DBGrid for WinForms Tutorials / Tutorial 8: Attaching a Drop-Down Control to a Grid Cell
In This Topic
    Tutorial 8: Attaching a Drop-Down Control to a Grid Cell
    In This Topic

    In this tutorial, you will learn how to attach a multicolumn True DBDropDown control to a grid cell. Unlike the built-in combo demonstrated in Tutorial 7: Displaying Translated Data with the Built-In Combo, the C1TrueDBDropDown control can be bound to a data source, which makes it ideal for data entry involving a secondary lookup table. The drop-down control appears whenever the user clicks a button within the current cell. This button appears automatically when the user gives focus to a column that has a drop-down control connected to it.

    Complete the following steps:

    1. Start with the project constructed in Tutorial 6: Defining Unbound Columns in a Bound Grid.
    2. Add a C1TrueDBDropDown control (C1TrueDBDropDown1) to the form. The icon for the C1TrueDBDropDown looks like the following:
    3. Go to the DataSource property and select Add Project Data Source from the drop-down. In the adapter's Data Source Configuration Wizard, either select a connection to C1NWind.mdb or create a new connection to this database. On the Choose your database objects page of the wizard, select the TypeID and TypeDesc fields in the CustType table and type "DsCustType" into the DataSet name box, and then finish out the wizard.
    4. Visual Studio adds the following code to the Load event of Form1 to fill the new dataset:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.CustTypeTableAdapter.Fill(Me.DsCustType.CustType)
      

      To write code in C#

      C#
      Copy Code
      this.CustTypeTableAdapter.Fill(this.DsCustType.CustType);
      
    5. Then again in the Load event of Form1, add the following code to set the C1TrueDBDropDown1 to the CustType column:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.C1TrueDBGrid1.Columns("CustType").DropDown = Me.C1TrueDBDropdown1
      

      To write code in C#

      C#
      Copy Code
      this.c1TrueDBGrid1.Columns["CustType"].DropDown = this.c1TrueDBDropdown1;
      
    6. In the Properties window set the DisplayMember property of the C1TrueDBDropDown1 to TypeID. This property informs the drop-down which column will be synchronized with the grid column that the drop-down is bound to.

    Run the program and observe the following:

    You've successfully completed attaching a drop-down control to a grid cell; this concludes tutorial 8