Rbn3D
Rbn3D

Reputation: 73

Win Forms DatagridView. How to add custom column from designer?

I've already created my custom DataGridViewSliderColumn class, which renders a TrackBar inside the cell.

My question is, how can I set the type of a column to my custom DataGridViewSliderColumn in the designer? (I have defined a lot of columns on the designer).

I've tried, but only predefined column types appear on the designer.

Is possible to set it without having to alter the column definition at runtime, by code?

Upvotes: 3

Views: 5220

Answers (1)

OhBeWise
OhBeWise

Reputation: 5454

Simple answer: After creating your custom column class, Rebuild your project.


For example, let's say we've created a custom Watermark column named DataGridViewWatermarkColumn. To add it to the designer options and consequently to the DataGridView, do the following:

  1. Rebuild the solution once the custom column class is complete.
  2. In the Designer for your DataGridView, click the arrow in the upper right corner to expand the DataGridView Tasks.

    An arrow to expand DataGridView Tasks.

  3. Select Add Column...

    The DataGridView Tasks popup for Columns and permissions.

  4. On the Add Column Dialog, select Type -> YourCustomColumn, then click Add.

    Add Column dialog showing the custom column added to the Type ComboBox options.

That's it. Do any editing necessary (such as setting the Column.WatermarkText in this example), run it, and enjoy.

Final result displaying a DataGridView with a custom watermark column and a normal TextBox column.

Upvotes: 2

Related Questions