FlexGrid for WinForms
Step 6 of 6: Include Custom Editors
Show AllShow All
Hide AllHide All

The C1FlexGrid has powerful built-in editors for entering text, masked text, selecting from lists, checkboxes, and more. But in some cases you may want to use a custom editor instead, perhaps one of the input controls in the C1Input library or a control that you wrote. Starting in version 2.5, the FlexGrid allows you to easily plug-in custom editors.

To attach a custom editor to the Sales column on our tutorial, start by adding a NumericUpDown control to the form.

  1. Set the following properties the Properties window to for the NumericUpDown control:
    Property Setting
    BorderStyle None
    DecimalPlaces 2
    Maximum 5000000
    ThousandsSeparator True
    Visible False
  2. Select Designer from the C1FlexGrid Tasks menu to bring up the grid's column editor.
  3. Select the Sales column (or Column 3 where the Sales figures will be), and set the Editor property to NumericUpDown1.

Run the program and observe the following:

Now run the project and try editing some values in the Sales column. Notice that the grid uses the NumericUpDown control instead of the built-in editors. The control is properly positioned, initialized, and managed. When you move the focus to a different cell, the value is stored in the grid.


But the custom editor doesn't behave exactly like the built-in ones. For example:

  1. When you start editing by typing a number, the old value isn't cleared.
  2. The size of the editor isn't exactly right (it looks a bit too small).
  3. There's a beep when you press ENTER to finish editing.

You can overcome these problems in a couple of ways. One way would be to use the editor's events, but that would make it difficult to reuse the control in other projects. Another way would be to create a derived class and implement some methods in the IC1EmbeddedEditor interface, as in the following code.

To write code in Visual Basic

To write code in C#

The previous code implements three methods:

See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Product Support Forum |  Documentation Feedback