DataGridView Custom ComboBox Column

I’m writing a .NET Winform application to communicate with and exercise the functionality of our forthcoming Color LCD. One of the attributes that can be selected is a font from a collection loaded into the display. Each entry in the collection has the font #, filename, foreground and background colors, spacing, transparency, etc.  In order to make it easy to ascertain which font is selected, I used an owner-draw drop list combobox that I found on CodeProject with a few changes to handle System.Drawing.Color properties and corrected the handling of the selected item coloring in the OnMeasureItem and OnDrawItem overrides:

MultiColumnComboBoxDropped

This works pretty good and allows the user to select a font based upon more that the name of the font.

I now needed to allow the user to perform this same selection when editing in a row of a DataGridView.  No problem I thought – just use this control in a custom DataGridViewComboBoxColumn class. I’m already using a customized DataGridViewButtonColumn that allows me to disable individual buttons in the column.

I again researched custom DataGridViewColumns and put together a derived class that I though should work. I had to derive a custom DataGridViewCell, DataGridViewEditingControl and DataGridViewColumn. Got everything to compile and run OK.

However it doesn’t quite work. When I try and BeginEdit() on one of these custom combobox cells, the mulitcolumncombobox class OnDropDown event gets called, but the EventArg is null. So you get a Null Reference Exception. The class looks like everything is connected up properly, the derived combobox has the correctly populated datasource, and it’s Item collection is correct.  Something is not hooked up correctly but I don’t know how to troubleshoot what is wrong. The call stack only shows the BeginEdit() call, <external code> and then the OnDropDown call with the null EventArgs parameter.  I spent about 1/2 a day trying to find solutions or comparable approaches without any luck.

So for right now, I removed this customized column, and am simply using a DataGridViewComboBoxColumn that just shows and edits the selected font using the name property of the datasource. It works, but it’s not as apparent to the user what the attributes of the selected font are.

I’m looking for some pointers on how to debug this or how to correctly hookup a derived combobox in custom DataGridViewComboBoxColumn. Maybe it needs to be derived from a DataGridViewTextBoxColumn instead ?

Thank you!

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: