如何将对象类型转换为DataGridViewcell类型..? [英] how to convert object type to DataGridViewcell type..?

查看:138
本文介绍了如何将对象类型转换为DataGridViewcell类型..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

推荐答案

您可能不能-除非它实际上是DataGridViewCell(或派生类)实例在第一位.您可以使用isas关键字进行检查:
You probably can''t - not unless it was actually a DataGridViewCell (or derived class) instance in teh first place. You can check with the is and as keywords:
if (myObject is DataGridViewCell)
   {
   ...
   }

DataGridViewCell dgvc = myObject as DataGridViewCell;
if (dgvc != null)
   {
   ...
   }

如果您尝试将对象放入DataGridView并需要一个新的单元格来容纳它,请创建一个新的单元格对象,并为要尝试处理的对象类型适当地设置其属性.

抱歉,这听起来有点含糊,但您并没有给我们太多...

If you are trying to put an object into a DataGridView and need a new cell to hold it though, create a new cell object and set it''s properties appropriately for the object type you are trying to handle.

Sorry if that sounds a bit vague, but you didn''t give us much to start with...


这篇关于如何将对象类型转换为DataGridViewcell类型..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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