C# – DataGridViewCell Inheritance – cell rendering

c++datagridviewwinforms

I am new to WinForms and C# so apologies if this is a bad question.

I am trying to create my own cell class for use in a DataGridView (eventually the plan is to show either a combo or textbox depending on some other property, but I cannot even get it to work as a normal textbox at the moment). The problem is that, whilst I can set the EditType and enter a value into the cell, whenever I am not in edit mode, I cannot see the cell or the value (I manged to enter the cell by tabbing and pressing F2). Here is the start of my class:

class DataGridViewComboOrTextBox : DataGridViewCell, IDataGridViewEditingCell
{

    public override Type EditType
    {
        get
        {
            return typeof(DataGridViewTextBoxEditingControl);
        }
    }

    public override Type FormattedValueType
    {
        get
        {
            return typeof(string);
        }
    }

I am wondering if I need to override the paint method or something?

Best Solution

The sample at http://msdn.microsoft.com/en-us/library/7tas5c80.aspx doesn't include cell painting code, but there are other things that you don't have. Take a look and see if it solves your problem.

Related Question