在编辑时更改为ComboBox的DataGridViewTextBoxColumn [英] DataGridViewTextBoxColumn that changes to ComboBox on editing

查看:175
本文介绍了在编辑时更改为ComboBox的DataGridViewTextBoxColumn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一个带有ComboBox列的DataGridView,它看起来像一个DataGridViewTextBoxColumn。

I want to show a DataGridView with a ComboBox column that looks like a DataGridViewTextBoxColumn.

在DataGridView中,显示了DataGridViewTextBoxColumn,并且当用户在此列中的单元格上设置Focus时,该单元格应更改为ComboBox。

In DataGridView I have the DataGridViewTextBoxColumn displayed and when the user sets Focus on a cell in this column, the cell should be changed to ComboBox.

我不知道必须重写哪个功能。

I don't know which function has to be overriden.

在DataGridTextBoxColumn中有编辑功能,我可以在此功能期间绘制我的组合框吗?

In DataGridTextBoxColumn there is the function Edit, can I can draw my combobox during this function?

推荐答案

除非我缺少任何内容-您应该能够简单地使用DataGridViewComboBoxColumn列类型。

Unless I'm missing something - you should be able to simply use the DataGridViewComboBoxColumn column type.

取决于您如何添加列您可以在添加列对话框的类型下拉列表中选择此类型,或以编程方式将其添加为:

Depending on how you are adding your columns you either chose this type in the Type drop down in the Add Column dialog or add it programarically like so:

DataGridViewComboBoxColumn col = new DataGridViewComboBoxColumn();
dataGridView1.Columns.Add(col);

要获得效果,您需要一个看起来像文本框的组合框,直到对其进行编辑为止则DataGridViewComboBoxColumn DisplayStyle属性为Nothing:

To achieve the effect you are after of a combobox that looks like a textbox until you edit it you set the DataGridViewComboBoxColumn DisplayStyle property to be Nothing:

List<string> names = new List<string> { "Joe", "Sally", "Kate" };

DataGridViewComboBoxColumn col = new DataGridViewComboBoxColumn();
col.DataSource = names;
col.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;

dataGridView1.Columns.Add(col);

您还可以通过EditingControlShowing事件访问DataGridView单元格的基础控件。

You can also access the underlying control of a DataGridView cell through the EditingControlShowing event.

这篇关于在编辑时更改为ComboBox的DataGridViewTextBoxColumn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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