I have a DataGridView the columns are set-up using:
<code>NameOfGridViewControl.Columns["ColumnName"].DisplayIndex = 0;
NameOfGridViewControl.Columns["ColumnName"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
...
</code>
<code>NameOfGridViewControl.Columns["ColumnName"].DisplayIndex = 0;
NameOfGridViewControl.Columns["ColumnName"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
...
</code>
NameOfGridViewControl.Columns["ColumnName"].DisplayIndex = 0;
NameOfGridViewControl.Columns["ColumnName"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
...
The content comes from a datasource and is added using:
<code>NameOfGridViewControl.DataSource = new source ...
</code>
<code>NameOfGridViewControl.DataSource = new source ...
</code>
NameOfGridViewControl.DataSource = new source ...
I want to add a column the table to display images, so I’ve tried:
<code>DataGridViewImageCell dgviCell = ((DataGridViewImageCell)dgvFound.Cells[icon];
</code>
<code>DataGridViewImageCell dgviCell = ((DataGridViewImageCell)dgvFound.Cells[icon];
</code>
DataGridViewImageCell dgviCell = ((DataGridViewImageCell)dgvFound.Cells[icon];
This results in an exception:
<code>System.InvalidCastException: `Unable to cast object type `System.Windows.Forms.DataGridViewTextBoxCell' to type 'System.Windows.Forms.DataGridViewImageCell'.'
</code>
<code>System.InvalidCastException: `Unable to cast object type `System.Windows.Forms.DataGridViewTextBoxCell' to type 'System.Windows.Forms.DataGridViewImageCell'.'
</code>
System.InvalidCastException: `Unable to cast object type `System.Windows.Forms.DataGridViewTextBoxCell' to type 'System.Windows.Forms.DataGridViewImageCell'.'
I’ve searched the source for ‘DataGridViewTextBoxCell’ and no instances are found, what do I need to do?