views:

663

answers:

1

Hi,

I am trying to customise a DataGridView cell to include a combobox and a text field. So far myCell class derives from DataGridViewTextBoxCell class. My class has a Combobox as a private member but I am not sure how I can render it. I am overriding the Pain method but I have no idea how to draw the combobox. I set its location to be at the origin of the cell and its size to be equal to cellBounds size. I know that if I was creating a combobox on a form I would have to add it to my forms controls list for example so it would get drawn but in this case I really dont know how to do it.

Note: I am not using any sort of sql db.

Ideally I would have a combobox displayed on the top half of my cell and a text box on the bottom half of my cell where users could change the text at runtime.

Does anyone know the best way to achieve this?

Thanks.

+1  A: 

I would try to derive from IDataGridViewEditingControl and a custom UserControl which has exacty your requirements (TextBox and ComboBox).
But check, if a ComboBox on its own is not already enough. Depending on the DropDownStyle your user can already change the content of the ComboBox.

tanascius
Thanks for your reply. I have created a NewColumn class, a NewCell class (derived from DataGridViewTextBoxCell) and a userControl that contains a combobox and a text box. Why did you mention to derive the newCell from IDataGridViewEditingControl? I still cant see the user control being drawn.
Well, at least in editmode you should see the custom usercontrol. The cell itself will still have to paint (pretend) that there is a combobox + a textbox. Maybe the [mono implementation](http://www.koders.com/csharp/fidA007D20790ED5F373E98CDAB06E10F7788C648E3.aspx) helps you?
tanascius
I will give it a try thanks.
I created an EditingControl that derives from myUserControl and IDataGridViewEditingControl and added the override functions as shown on the example you sent. I can see my control now (event though I have to click on the cell or type something for it to show up) :)On resize it is not repainting it properly... A good starting point anyway, thanks!
Just noticed that InitializeEditingControl() is the one responsible for displaying my user control on the cell but it is only called once I click on the cell. Calling it just after I add a row breaks as it says the state of the cell is not right. Any ideas how I can solve this?Regarding resizing, calling editControl.Invalidate() doesnt redraw my user control... there must be something else that needs to be done, no?