Custom cell editor in DataGridView

Answered
0
0

Hi,

is it possible to set custom cell editor dynamically on runtime ?

Best,

Alexander

  • You must to post comments
Best Answer
1
0

Hi Alexander,

Try the attached sample. It shows how to dynamically create a cell editor and how to store the custom value in the cell. It displays 10 columns and 1000 rows and creates 5 different cell editors on different rows: DateTimePicker, ComboBox, NumericUpDown, TrackBar and TextBox with auto suggest list.

The sample is somewhat rudimentary since it creates a new editor each time edit mode is started. You can cache editors or create new ones according to your requirements.

You can also assign the Column.Editor property only once instead of recreating the editor each time.

Additionally, if your editor implements the IDataGridViewEditingControl interface you don’t have to store the custom value in EndEdit.

HTH

Best,

Luca

 

  • You must to post comments
0
0

I was having real trouble getting a non-bound DataGridView working with rows of different data types, working almost as a Property Grid (couldn’t use a Property Grid as it’s not as user friendly and 100 times more complicated to set up, not easily extendible at run time etc.). No TypeConverters, custom controls etc. required – thank you Luca!

  • Luca (ITG)
    You are welcome. BTW the PropertyGrid uses the DataGridView and assigns custom cells. But the ComponentModel system is quite complex. In your DataGridView, if all you need to do is mix cells of different types, you can simply replace a cell: i.e. row.Cells[3] = new DataGridViewCellBoxCell();
  • You must to post comments
0
0

Thanks it worked!

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.