Certain types of cells may require sophisticated editors other than text boxes or drop-down lists. For example, if a column contains file names or a color, it should be edited with a dialog box.
In these cases, you should set the ComboList property to an ellipsis ("…"). The control will display a button next to the cell and will fire the CellButtonClick event when the user clicks on it. You can trap the event, show the dialog box, and update the cell' s contents with the user's selection.
If you add a pipe character before the ellipsis, then the user will also be allowed to edit the cell contents by typing into the cell.
By default, the cell buttons display the ellipsis. You can assign pictures to the cell buttons using the CellButtonImage property.
The example below shows how you can use cell buttons to display a color picker dialog box for choosing a color in a column.
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
' Set up color column. Dim c As C1.Win.C1FlexGrid.Column = _flex.Cols(1) c.DataType = GetType(Color) ' Show cell button. c.ComboList = "..." |
To write code in C#
C# |
Copy Code
|
---|---|
// Set up color column. Column c = _flex.Cols[1]; c.DataType = typeof(Color); // Show cell button. c.ComboList = "..."; |
This code sets up the column so the user can click a button and select a color from a dialog box. The next step is the code that handles clicks on the cell button:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub _flex_CellButtonClick(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.RowColEventArgs) Handles _flex.CellButtonClick ' Create color picker dialog. Dim clrDlg As New ColorDialog() ' Initialize the dialog. If _flex(e.Row, e.Col) Is GetType(Color) Then clrDlg.Color = _flex(e.Row, e.Col) End If ' Get new color from dialog and assign it to the cell. If clrDlg.ShowDialog() = Windows.Forms.DialogResult.OK Then _flex(e.Row, e.Col) = clrDlg.Color End If End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void _flex_CellButtonClick( object sender, RowColEventArgs e) { // Create color picker dialog. ColorDialog clrDlg = new ColorDialog(); // Initialize the dialog. if (_flex[e.Row, e.Col] == typeof(Color)) { clrDlg.Color = (Color)_flex[e.Row, e.Col]; } // Get new color from dialog and assign it to the cell. if (clrDlg.ShowDialog() == DialogResult.OK) { _flex[e.Row, e.Col] = clrDlg.Color; } } |