本文介绍了我怎么主机显示和编辑在DataGridViewCell的控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过如何在Windows主机控制窗体DataGridView细胞,说明如何举办一个控制用于编辑一个DataGridView的单元格。但我怎么能承载控制显示单元?

I've seen How to: Host Controls in Windows Forms DataGridView Cells which explains how to host a control for editing a cell in a DataGridView. But how can I host a control for displaying a cell?

我需要显示一个文件名和在同一细胞的按钮。我们的UI设计师是一名平面设计师不是程序员,所以我必须要匹配code到什么他绘制的,无论是可能的 - 或明智的 - 或者不是。我们使用VS2008,写在C#.NET 3.5,如果有差别。

I need to display a file name and a button in the same cell. Our UI designer is a graphic designer not a programmer, so I have to match the code to what he's drawn, whether it's possible - or wise - or not. We're using VS2008 and writing in C# for .NET 3.5, if that makes a difference.

更新:在网建议创建一个自定义的DataGridViewCell它承载一个小组的第一步;没有人这样做呢?

UPDATE: The 'net suggests creating a custom DataGridViewCell which hosts a panel as a first step; anyone done that?

推荐答案

根据您的更新,创建自定义的的DataGridViewCell 是这样做的方法。我已经做到了,而且它不需要从例如code可以从MSDN这么多的修改。就我而言,我需要一帮自定义编辑控件,所以我最终从 DataGridViewTextBoxCell 的DataGridViewColumn 继承。我插进我班(从 DataGridViewTextBoxCell 一个继承),它实现了一个新的自定义控制 IDataGridViewEditingControl ,而这一切只工作。

As per your "UPDATE", creating a custom DataGridViewCell is the way this is done. I've done it, and it doesn't require that much modification from the example code available from the MSDN. In my case, I needed a bunch of custom editing controls, so I ended up inheriting from DataGridViewTextBoxCell and DataGridViewColumn. I inserted into my class (the one inherited from DataGridViewTextBoxCell) a new custom control which implemented IDataGridViewEditingControl, and it all just worked.

我想,你的情况,你可以写一个 PanelDataGridViewCell 这将包含一个控制 MyPanelControl 这将继承从面板和实施 IDataGridViewEditingControl

I suppose that in your case, you could write a PanelDataGridViewCell which would contain a control MyPanelControl which would inherit from Panel and implement IDataGridViewEditingControl.

这篇关于我怎么主机显示和编辑在DataGridViewCell的控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!