Custom - DataGridViewColumn / DataGridViewCell

J

John J. Hughes II

I am trying to create a custom DataGridViewCell which is "NOT" derived from
DataGridViewTextBoxColumn. The painting works fine but I am unable to get
the control into edit mode.

Do I need to manually handle the OnClick, something else, or is there
somewhy to set the edit control?

Edit type is called when the cell is clicked so it seems to be doing
something.

Regards,
John

class clsPMenuColumn : DataGridViewColumn
{
private System.Data.DataSet displayStrings;
public System.Data.DataSet DisplayStrings
{
set
{
this.displayStrings = value;
}
get
{
return this.displayStrings;
}
}

public override object Clone()
{
clsPMenuColumn cell = (clsPMenuColumn)base.Clone();
cell.DisplayStrings = this.DisplayStrings;

return cell;
}

public override DataGridViewCell CellTemplate
{
get
{
return base.CellTemplate;
}
set
{
if (value != null &&
!value.GetType().IsAssignableFrom(typeof(clsPMenuCell)))
throw new InvalidCastException("Must be a Pmenu cell");

base.CellTemplate = value;
}
}
}
}

class clsPMenuCell : DataGridViewCell
{
private System.Data.DataSet DisplayStrings
{
get
{
if (base.OwningColumn is clsPMenuColumn)
return ((clsPMenuColumn)base.OwningColumn).DisplayStrings;
return null;
}
}

public override object DefaultNewRowValue
{
get
{
return new clsMenuStructure();
}
}

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

public override Type ValueType
{
get
{
return typeof(clsMenuStructure);
}
}

public clsPMenuCell() : base()
{
}

protected override void Paint(System.Drawing.Graphics graphics,
System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds,
int rowIndex, DataGridViewElementStates cellState, object value, object
formattedValue, string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts
paintParts)
{
/// do painting here
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top