无法将类型为“DataGridViewTextBoxCell”的对象强制转换为类型“TreeGridCell“

xuyile510824 2012-10-03 07:07:48

无法将类型为“System.Windows.Forms.DataGridViewTextBoxCell”的对象强制转换为类型“AdvancedDataGridView.TreeGridCell”。

void cells_CollectionChanged(object sender, System.ComponentModel.CollectionChangeEventArgs e)
{
// Exit if there already is a tree cell for this row
if (_treeCell != null) return;

if (e.Action == System.ComponentModel.CollectionChangeAction.Add || e.Action == System.ComponentModel.CollectionChangeAction.Refresh)
{
TreeGridCell treeCell = null;

if (e.Element == null)
{
foreach (DataGridViewCell cell in base.Cells)
{
if (cell.GetType().IsAssignableFrom(typeof(TreeGridCell)))
{
treeCell = (TreeGridCell)cell; //错误出现的位置
break;
}

}
}
else
{
treeCell = e.Element as TreeGridCell;
}

if (treeCell != null)
_treeCell = treeCell;
}
}

咋回事呢?
...全文
350 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuyile510824 2012-10-03
  • 打赏
  • 举报
回复
其实这段代码在c#.NET环境中确实可以运行,我输出运行库后想在VB.NET中运行就提示错误了。

是不是vs2010版本过高的问。
dalmeeme 2012-10-03
  • 打赏
  • 举报
回复
类型转换不了,比如说:你要把Button转换成TextBox,你说能转吗?
dbfC#DataGridView中的常用技巧 只列出技巧部分,后面会有补充 0(最基本的技巧). 获取某列中的某行(某单元格)中的内容 this.currentposition = this.dataGridView1.BindingContext [this.dataGridView1.DataSource, this.dataGridView1.DataMember].Position; bookContent = this.database.dataSet.Tables[0].Rows [this.currentposition][21].ToString().Trim(); MessageBox.Show(bookContent); 1、自定义列 //定义列宽 this.dataGridView1.Columns[0].Width = 80; this.dataGridView1.Columns[1].Width = 80; this.dataGridView1.Columns[2].Width = 180; this.dataGridView1.Columns[3].Width = 120; this.dataGridView1.Columns[4].Width = 120; Customize Cells and Columns in the Windows Forms DataGridView Control by Extending Their Behavior and Appearance Host Controls in Windows Forms DataGridView Cells 继承 DataGridViewTextBoxCell 类生成新的Cell类,然后再继承 DataGridViewColumn 生成新的Column类,并指定 CellTemplate为新的Cell类。新生成的Column便可以增加到DataGridView中去。 2、自动适应列宽 Programmatically Resize Cells to Fit Content in the Windows Forms DataGridView Control Samples: DataGridView.AutoSizeColumns( DataGridViewAutoSizeColumnCriteria.HeaderAndDisplayedRows); DataGridView.AutoSizeColumn( DataGridViewAutoSizeColumnCriteria.HeaderOnly, 2, false); DataGridView.AutoSizeRow( DataGridViewAutoSizeRowCriteria.Columns, 2, false); DataGridView.AutoSizeRows( DataGridViewAutoSizeRowCriteria.HeaderAndColumns, 0, dataGridView1.Rows.Count, false); 3、可以绑定并显示对象 Bind Objects to Windows Forms DataGridView Controls 4、可以改变表格线条风格 Change the Border and Gridline Styles in the Windows Forms DataGridView Control Samples: this.dataGridView1.GridColor = Color.BlueViolet; this.dataGridView1.BorderStyle = BorderStyle.Fixed3D; this.dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None; this.dataGridView1.RowHeadersBorderStyle = DataGridVie

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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