问题描述
我正在尝试创建一个负责控制的 DataGridView
单元格类(所有的时间,而不仅仅是编辑)。到目前为止,我的方法是将控件添加到网格中,并尝试将其位置与单元格的位置同步。
I'm trying to create a DataGridView
cell class which hosts a control (all the time, not just while editing). So far, my approach has been to add the control to the grid and try to synchronise its position with that of the cell.
是否可以保留单元格屏幕上,将鼠标和键盘事件路由到它,并将其绘制到单元格上?
Would it be possible instead to keep the cell offscreen, route mouse and keyboard events to it, and paint it onto the cell?
更新:通过'offscreen',我不是说应该添加到另一个控件,使其不显示;我的意思是根本不应该添加到另一个控件。
UPDATE: By 'offscreen', I don't mean that it should be added to another control such that it isn't displayed; I mean that it should never be added to another control at all.
推荐答案
您可以创建一个控件,而不将其添加到表单中,然后使用它作为Cell编辑器,只要你需要。通常使用网格,当您单击单元格进行编辑时,将要创建一个新的控件并将其放在正确的位置,否则将使用现有的控件。您可以通过创建自己的自定义单元格/列类型来简化此过程。请参阅此MSDN页面:。
You can create a control without adding it to the form, then using it as the Cell editor whenever you need to. Usually with grids, when you click on a cell to edit it, it's going to either create a new control and put it in the right place, or it's going to use an existing control. You can make this process a lot easier by creating your own custom cell / column types. See this MSDN page: http://msdn.microsoft.com/en-us/library/7fb61s43.aspx.
大多数网格(包括DataGridView和第三方网格)都有添加自定义单元格的功能。
Most grids (including DataGridView and 3rd Party Grids) have a facility for adding custom cells.
这篇关于我可以使用“屏幕外”控件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!