如何在DataGridViewColumnHeaderCell类中使用自定义控件(用户控件或继承的控件)来编写自定义headerCell? [英] How to use a custom control (User control or a inherited control) into DataGridViewColumnHeaderCell class to write a custom headerCell?

查看:138
本文介绍了如何在DataGridViewColumnHeaderCell类中使用自定义控件(用户控件或继承的控件)来编写自定义headerCell?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..
我想为从dataGridView继承的控件编写自定义headerCell.
如何在DataGridViewColumnHeaderCell类中使用自定义控件(用户控件或继承的控件)?对于通用控件,例如通过CheckBoxRenderer.DrawCheckBox(...) .我只想知道用户控制或继承的控件怎么可能????
谢谢..

假设这是我的自定义headerCell:
< pre lang ="c#">
公共类DataGridViewComboBoxHeaderCell:DataGridViewColumnHeaderCell
{


公共DataGridViewComboBoxHeaderCell()
{

}
UnitConvertorComboBox.UnitConvertorComboBox组合=新的UnitConvertorComboBox.UnitConvertorComboBox();

受保护的重写void Paint(System.Drawing.Graphics图形,
System.Drawing.Rectangle clipBounds,
System.Drawing.Rectangle cellBounds,
int rowIndex,
DataGridViewElementStates dataGridViewElementState,
对象值,
对象formattedValue,
字符串errorText,
DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
base.Paint(graphics,clipBounds,cellBounds,rowIndex,
dataGridViewElementState,值,
formattedValue,errorText,cellStyle,
advancedBorderStyle,paintParts);
}
}
</pre>
这是我的自定义控件,它继承自combobox:
< pre lang ="c#">
公共局部类UnitConvertorComboBox:ComboBox
{
//构造函数
公共UnitConvertorComboBox()
{
}

</pre>

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>

推荐答案

我已经通过注释中提到的方式解决了.但是有些事情我只能再打一次.效果很好!!!
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!!!


这篇关于如何在DataGridViewColumnHeaderCell类中使用自定义控件(用户控件或继承的控件)来编写自定义headerCell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆