Windows 窗体 DataGridView 控件在同一列中具有不同的控件类型 [英] Windows Forms DataGridView control have different control types in the same column

查看:37
本文介绍了Windows 窗体 DataGridView 控件在同一列中具有不同的控件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 DataGridView 中执行以下操作:

Is it possible to do the following in a DataGridView:

在同一列中,我想更改 DataGridViewTextBoxColumn 和 DataGridViewComboBoxColumn 之间每一行的控件类型?

In the same column I want to change the control type of each row between DataGridViewTextBoxColumn and DataGridViewComboBoxColumn?

(这是因为有时我想显示一个下拉列表,有时我只想让用户输入一个手绘值).

(this is because sometimes I want to display a drop down list and other times I just want the user to enter a freehand value).

谢谢,

附言我正在使用 C#

推荐答案

您可以创建自己的继承自 DataGridViewCell 的类,并覆盖适当的虚拟成员(InitializeEditingControls、EditType,也许还有其他一些).然后,您可以使用此类的实例作为单元格模板创建一个 DataGridViewColumn

You could create your own class inherited from DataGridViewCell, and override the adequate virtual members (InitializeEditingControls, EditType, maybe a few others). You can then create a DataGridViewColumn with an instance of this class as the cell template

这篇关于Windows 窗体 DataGridView 控件在同一列中具有不同的控件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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