I'm trying to display image in datagridview cells, depending on a condition. My code seems right but i don't know why it doesn't display anything.
for (int k = 0; k <= calculGridView.Rows.Count-1; k++)
{
Image img;
DataGridViewImageCell cell = (DataGridViewImageCell)calculGridView.Rows[k].Cells["image"];//image is a datagridviewimagecolumn
if (calculGridView.Rows[k].Cells["societate"].Value.ToString() == "BetaCar")
{
img = Image.FromFile(@"C:\\Users\\Vio\\Desktop\\New folder\\betacar.jpg");
cell.Value = img;
}
}
Does anybody know what's wrong? or maybe another solution?
Does anybody know what's wrong? or maybe another solution?


VulpesRank #55 · 29.2K reputationPosted Apr 16, 2013, 5:49 AM EDT
Are you sure are the cell contains "BetaCar" and not "Beta Car" (or the same word(s) with different casing) and that there's no white-space at the end which needs trimming off before the comparison is made?
VulpesRank #55 · 29.2K reputationPosted Apr 15, 2013, 1:20 PM EDT
img = Image.FromFile(@"C:\\Users\\Vio\\Desktop\\New folder\\betacar.jpg");
you don't want the @ in front because the backslashes have been doubled.
Violeta Popa132 reputationPosted Apr 15, 2013, 10:52 PM EDT