ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

C1TrueDBGrid.ButtonClick Event

Occurs whenever a button is clicked in a cell.

[Visual Basic]

Public Event ButtonClick As ColEventHandler

[C#]

public event ColEventHandler ButtonClick

[Delphi]

public property ButtonClick: ColEventHandler read remove_ButtonClick write add_ButtonClick;

Remarks

This event is raised when the current cell's built-in button is clicked. The built-in button is enabled for a column when its C1DisplayColumn.Button property is set to True, its C1DataColumn.DropDown property is set to the name of a valid C1TrueDBDropdown control, or the ValueItems.Presentation property of its associated ValueItems collection is set to one of the combo box options.

Typically, the column button is enabled when wanting to drop-down a Visual Studio control (such as the built-in combo box, a bound list box, or even another C1TrueDBGrid control) for editing or data entry. When the button in the current cell is clicked, the ButtonClick event will be raised. Code can then be written to drop-down the desired control from the cell.

Example

The following code uses the Fill method to add items from the data source to the list box and the C1DisplayColumn.Button property to place a button in the CustType column:

·      Visual Basic

       Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

           Me.ContactsTableAdapter.Fill(Me.DsContacts.Contacts)

           ' Add customer types to ListBox1.

           With Me.ListBox1

               .Items.Add("Prospective")

               .Items.Add("Normal")

               .Items.Add("Buyer")

               .Items.Add("Distributor")

               .Items.Add("Other")

               .Visible = False

           End With

           ' Place a button in the CustType column.

           Me.C1TrueDBGrid1.Splits(0).DisplayColumns("CustType").Button = True

       End Sub

·      C#

       private void Form1_Load(System.object sender, System.EventArgs e)

       {

           this.ContactsTableAdapter.Fill(this.DsContacts.Contacts);

           // Add customer types to listBox1.

           listBox1.Items.Add("Prospective");

           listBox1.Items.Add("Normal");

           listBox1.Items.Add("Buyer");

           listBox1.Items.Add("Distributor");

           listBox1.Items.Add("Other");

           listBox1.Visible = false;

           // Place a button in the CustType column.

           this.c1TrueDBGrid1.Splits[0].DisplayColumns["CustType"].Button = true;

       }

·      Delphi

       procedure TWinForm.TWinForm_Load(sender: System.Object; e: System.EventArgs);

       begin

         // Add customer types to ListBox1.

         ListBox1.Items.Add('Prospective');

         ListBox1.Items.Add('Normal');

         ListBox1.Items.Add('Buyer');

         ListBox1.Items.Add('Distributor');

         ListBox1.Items.Add('Other');

         ListBox1.Visible = False;

         // Place a button in the CustType column.

         Self.C1TrueDBGrid1.Splits[0].DisplayColumns['CustType'].Button := True;

       end;

After the built-in button is enabled for a column, you can use the ButtonClick event to drop down the list box:

·      Visual Basic

       Private Sub C1TrueDBGrid1_ButtonClick(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.ColEventArgs) Handles C1TrueDBGrid1.ButtonClick

           With ListBox1

               .Left = Me.C1TrueDBGrid1.Left + Me.C1TrueDBGrid1.RecordSelectorWidth + Me.C1TrueDBGrid1.Splits(0).DisplayColumns(0).Width + Me.C1TrueDBGrid1.Splits(0).DisplayColumns(1).Width

               .Top = Me.C1TrueDBGrid1.Top + Me.C1TrueDBGrid1.RowTop(Me.C1TrueDBGrid1.Row)

               .Visible = True

               .Select()

           End With

       End Sub

·      C#

       private void c1TrueDBGrid1_ButtonClick(object sender,  C1.Win.C1TrueDBGrid.ColEventArgs e)

       {

           listBox1.Left = this.c1TrueDBGrid1.Left + this.c1TrueDBGrid1.RecordSelectorWidth + this.c1TrueDBGrid1.Splits[0].DisplayColumns[0].Width + this.c1TrueDBGrid1.Splits[0].DisplayColumns[1].Width;

           listBox1.Top = this.c1TrueDBGrid1.Top + this.c1TrueDBGrid1.RowTop(this.c1TrueDBGrid1.Row);

           listBox1.Visible = true;

           listBox1.Select();

       }

·      Delphi

       procedure TWinForm.C1TrueDBGrid1_ButtonClick(sender: System.Object; e: C1.Win.C1TrueDBGrid.ColEventArgs);

       begin

         ListBox1.Left := C1TrueDBGrid1.Left + C1TrueDBGrid1.RecordSelectorWidth + C1TrueDBGrid1.Splits[0].DisplayColumns[0].Width + C1TrueDBGrid1.Splits[0].DisplayColumns[1].Width + C1TrueDBGrid1.Splits[0].DisplayColumns[2].Width;

         ListBox1.Top := C1TrueDBGrid1.Top + C1TrueDBGrid1.RowTop(C1TrueDBGrid1.Row);

         ListBox1.Visible := True;

         ListBox1.Select;

       end;

For more details on the ButtonClick event see Tutorial 9 - Attaching an Arbitrary Drop-Down Control to a Grid Cell and the Detecting In-Cell Button Clicks topics.

See Also

C1TrueDBGrid Class | C1TrueDBGrid Members | C1.Win.C1TrueDBGrid Namespace


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.