简体   繁体   English

在DataGridView中托管自定义控件-C#WinForm

[英]Hosting custom control in DataGridView - C# WinForm

I looked at http://msdn.microsoft.com/en-us/library/7tas5c80.aspx for reference and it makes sense as far as editable column goes. 我查看了http://msdn.microsoft.com/en-us/library/7tas5c80.aspx作为参考,就可编辑列而言,它是有意义的。

The question is how do I host a "view only" custom control in a DataGridView (WinForm and C#)? 问题是如何在DataGridView(WinForm和C#)中托管“仅查看”自定义控件?

从DataGridViewCell派生并重写Paint方法。

Another easy way would be to make that column one of the "DataKeyNames" columns of the grid. 另一种简单的方法是使该列成为网格的“ DataKeyNames”列之一。 Any field that is considered a "Key" is by default disabled from a user editing it. 默认情况下,任何被视为“键”的字段都将禁止用户对其进行编辑。 However, if you deal with object analysis on "clicked" on records for editing, or other, the array of returned keys will be in the same sequence as they are listed in the DataKeyNames property. 但是,如果您对记录进行“单击”以进行编辑或其他操作进行对象分析,则返回键的数组将与DataKeyNames属性中列出的顺序相同。 So, even though you may be ignoring the actual value as a "Key", it can act to disable it. 因此,即使您可能忽略了作为“键”的实际值,也可以将其禁用。

HTH 高温超导

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

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