简体   繁体   English

创建自定义列类型?

[英]creating a custom column type?

when I try to add a column to my datagrid at design time 当我尝试在设计时将一列添加到我的数据网格中时
there are custom types for the column and i must choose one of these types as an example "dataGridViewTextBoxColumn" 列有自定义类型,我必须选择这些类型之一作为示例“ dataGridViewTextBoxColumn”
how can I create a custom column type ? 如何创建自定义列类型?
what I want is a custom Type for my column called "dataGridViewNumberTextBoxColumn" that i can choose it for my datagrid at design time 我想要的是自定义类型的列,称为“ dataGridViewNumberTextBoxColumn”,我可以在设计时为我的datagrid选择它

I am using c# and .Net and a windows form application 我正在使用C#和.Net和Windows Form应用程序
thanks 谢谢

Basically, you need to descend from the base class DataGridViewColumn and create your own visual display. 基本上,您需要从基类DataGridViewColumn并创建自己的可视显示。

See here for an example of how to do this: 有关如何执行此操作的示例,请参见此处:

只需从Microsoft获得DataGridViewNumericUpDownColumn

Obviously you can't inherit form TextBox as it is not object that inherits from DataGridViewColumn. 显然,您不能继承TextBox窗体,因为它不是从DataGridViewColumn继承的对象。

On the other hand, you can inherit from any object that inherits from this object. 另一方面,您可以继承任何从该对象继承的对象。

Note that when using your new Column class, you must cast DataGridView.Columns[index] to it, otherwise you won't see any of its properties or methods. 请注意,在使用新的Column类时,必须将DataGridView.Columns [index]强制转换为它,否则将看不到其任何属性或方法。 Or you can also create new class from DataGridView that does this in new property. 或者,您也可以从DataGridView创建新类,并在new属性中执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM