True DBGrid for WinForms supports a variety of in-cell button options for the current cell or for all cells within specified columns. Use in-cell buttons to indicate that a list of choices is available, to perform a command associated with the contents of the cell, or to display an arbitrary control or form for editing.
To enable the in-cell button for a C1DisplayColumn object, set its Button property to True in code:
C# |
コードのコピー
|
---|---|
this.c1TrueDBGrid1.Splits[0].DisplayColumns[0].Button = true; |
The Button property is also enabled when the column's DropDown property is set to the name of a C1TrueDBDropDown control, or when the Presentation property of the associated ValueItemCollection object is set to one of the combo box options.
By default, the in-cell button displays only for the current cell, as shown in the following image:
However, by setting the column's ButtonAlways property to True, you can force the in-cell button to be displayed in every row:
To render the current cell as a non-editable command button within a C1DisplayColumn object, set its ButtonText property to True in code:
C# |
コードのコピー
|
---|---|
this.c1TrueDBGrid1.Splits[0].DisplayColumns[0].ButtonText = true; |
When a cell within the column receives focus, it is rendered as a standard Windows command button using the cell text as the caption. The cell text is not centered automatically, but respects the column's horizontal and vertical alignment settings:
If both the Button and ButtonText properties are True, the ButtonText property takes precedence.
As with the default in-cell button, set the column's ButtonAlways property to True to force all of its cells to be displayed as command buttons. Only the current cell is drawn with a focus rectangle, however:
The ButtonClick event is provided so that code can respond when the user clicks the in-cell button. Its syntax is as follows:
C# |
コードのコピー
|
---|---|
private void C1TrueDBGrid1_ButtonClick( object sender, C1.Win.C1TrueDBGrid.ColEventArgs e) |
In-cell buttons always fire this event when clicked, regardless of whether they were enabled by the Button or ButtonText properties. An example of the ButtonClick event was presented earlier in the section Working with Text.
By default, True DBGrid for WinForms uses a down arrow for the in-cell button.
However, the button bitmap can be changed for a C1DisplayColumn object at design time by setting the ButtonPicture property in code:
C# |
コードのコピー
|
---|---|
this.c1TrueDBGrid1.Columns[0].ButtonPicture = System.Drawing.Image.FromFile("dollar.bmp"); |
The grid automatically draws the edges corresponding to the button's up/down states as appropriate, so only the interior image of the button needs to be provided.