I want to host a custom control for datagridviewcell.
the only good reference i have was http://msdn.microsoft.com/en-us/library/7tas5c80.aspx
However, i want the cell to display my own usercontrol instead on
public class CustomCell : DataGridViewTextBoxCell
{
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)
{
base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value,
formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
}
}
Can anyone guide me how to do it ?
In order to save on resources, the cells in a
DataGridViewcontrol spend most of their time in display mode, only changing to edit mode when the user enters the cell using the mouse or keyboard. The example you referred to in your question is regarded as best practice, because the editing control (in that case, aDateTimePicker, but could just as easily be your own custom user control) only ever appears in edit mode, and thus only for one cell at a time.When the cell is not in edit mode, it should render an equivalent representation of its value using logic inside the
Paintmethod of your subclass ofDataGridViewCell. You could do this in one of several ways:ControlPaintorVisualStyleRenderer(note: this involves a lot of extra work).In most cases, the first option will be sufficient; only attempt one of the other approaches if it is important for the cell to look EXACTLY the same as your editing control.