类型“System.Windows.Forms.DataGridViewCell”的值无法转换为“System.Windows.Forms.Control”

lmhcs 2011-02-20 06:08:11
我写了一个控件,有个属性给用户传入要操作的控件。
Friend Property CPControl() As Control
Get
Return _PControl
End Get
Set(ByVal value As Control)
_PControl = value
If TypeOf value Is TextBox Then
mTextbox = Nothing
mTextbox = CType(value, TextBox)
' ElseIf TypeOf value Is DataGridViewCell Then
End If
End Set
End Property

结果我发现,当要传入的控件是datagridviewcell时,系统提示
类型“System.Windows.Forms.DataGridViewCell”的值无法转换为“System.Windows.Forms.Control”
我该怎么更改属性的类型的才能传入DataGridViewCell 或者文本框等基于control的控件呢 。
...全文
550 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lmhcs 2011-03-16
  • 打赏
  • 举报
回复
呵呵,好久没有来,就是用object解决。
yanlongwuhui 2011-02-28
  • 打赏
  • 举报
回复
声明为OBJECT,CPControl中根据类型先进行转换,后进行操作;
或是不要传入DataGridViewCell,而是DataGridView
lmhcs 2011-02-20
  • 打赏
  • 举报
回复
可System.Windows.Forms不是类型呢 。
lmhcs 2011-02-20
  • 打赏
  • 举报
回复
嗯。难道我把 声明成System.Windows.Forms?
wuyq11 2011-02-20
  • 打赏
  • 举报
回复
System.Object
System.Windows.Forms.DataGridViewElement
System.Windows.Forms.DataGridViewCell

System.Windows.Forms.Control
System.Windows.Forms.ButtonBase
System.Windows.Forms.Button

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧