It is relatively easy to have a column of type DataGridViewImageColumn
display text in specific cells.
All you have to do is replace the desired DataGridViewTextBoxCell
cell.
So, for example, if I add the following image column to my grid:
DataGridViewImageColumn imageColumn = new DataGridViewImageColumn(); imageColumn .Name = "ImageColumn"; imageColumn .HeaderText = "An Image!"; Image i = Image.FromFile(@"C:\Pictures\TestPicture.jpg"); imageColumn.Image = i; dataGridView1.Columns.Add(imageColumn);
You can replace this cell with such text (here in the button handler, but you can also do it somewhere, like in the full data binding handler).
private void button1_Click(object sender, EventArgs e) { dataGridView1.Rows[3].Cells["ImageColumn"] = new DataGridViewTextBoxCell(); dataGridView1.Rows[3].Cells["ImageColumn"].Value = "Some text!"; }
This solution leaves a little work for you if you need different images (you need to bind to a property like image), and if you need different text. Since the Value property of an image column is of type Image, you cannot use the same binding.
You can create your own column with an overridden image that would handle this, but that would be a bit of work that might not pay for itself, but simply set the value for cells where you want the text directly.
source share