如何将自定义属性添加到自定义dataGridview列? [英] How can i add custom property to column of custom dataGridview?
问题描述
大家好,
我创建了由dataGridView继承的新组件。我可以为mydataGridView添加一个新的可浏览属性。另外我想为mydataGridView的列添加属性。它应该是可浏览的。因为我想在属性窗口看到。它的类型并不重要,可能是int或string。然后我应该在代码中使用mydataGridView1.Columns [0] .MyProperty = 100;。
我该怎么做?
谢谢,
Ibrahim Uylas
Hi Everyone,
I created new component that is inherited by dataGridView. I can add a new browsable property to mydataGridView. Also I want to add property for column of mydataGridView. It should be browsable. Because i want to see on properties windows. It''s type is not important, may be int or string. Then i should use in code like "mydataGridView1.Columns[0].MyProperty = 100;".
How can i do this?
Thanks,
Ibrahim Uylas
推荐答案
您可以创建从不同DataGridViewColumn类型派生的新类并定义派生类中的新属性。
You can create new classes derived from different DataGridViewColumn types and define the new property in your derived class.
public class DataGridTextBoxColumnEx : DataGridViewTextBoxColumn
{
[Browsable(true)]
public int Bump
{
get;
set;
}
}
并在UI设计器类中使用它。
and use it like this in your UI designer class.
private void InitializeComponent()
{
//replace the following code all the references to your derived class
this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
to
this.Column2 = new DataGridTextBoxColumnEx();
}
这篇关于如何将自定义属性添加到自定义dataGridview列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!