Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello every body..
I want to write a custom headerCell for a control inherited from dataGridView.
how it's possible to use a custom control(user control or a inherited control) into a DataGridViewColumnHeaderCell class? for a common control it's easy for example for check box by: CheckBoxRenderer.DrawCheckBox(...); . I just want to know how it's possible with user control or a inherited one????
Thanks ..

This is suppose to be my custom headerCell:
<pre lang="c#">
public class DataGridViewComboBoxHeaderCell:DataGridViewColumnHeaderCell
{


public DataGridViewComboBoxHeaderCell()
{

}
UnitConvertorComboBox.UnitConvertorComboBox Combo = new UnitConvertorComboBox.UnitConvertorComboBox();

protected override void Paint(System.Drawing.Graphics graphics,
System.Drawing.Rectangle clipBounds,
System.Drawing.Rectangle cellBounds,
int rowIndex,
DataGridViewElementStates dataGridViewElementState,
object value,
object formattedValue,
string errorText,
DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
base.Paint(graphics, clipBounds, cellBounds, rowIndex,
dataGridViewElementState, value,
formattedValue, errorText, cellStyle,
advancedBorderStyle, paintParts);
}
}
</pre>
And this is my custom control which inherited from combobox:
<pre lang="c#">
public partial class UnitConvertorComboBox : ComboBox
{
//Constructor
public UnitConvertorComboBox()
{
}

</pre>
Posted
Comments
alizadeh91 13-Dec-11 9:50am    
I've found a temporary solution: This.DataGridView.Controls.Add(AnyControl);
but i dont like that!!! i want to add this via headerCell not by DataGridView
Common guys help me!!!

1 solution

I've solved by the way which was mentioned in comments. But there is something that i must call just one time not any more. It works fine!!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900