can anybody tel me ? to do in datagridview at runtime.actualy that s textboxcolumn. whenerver click the cell it should show the background imag. is it possible in C# windows.if u any idea plz help me out.thnks

Yes you can

implement the cell

private void dataGridView1_CellClick(object sender,
DataGridViewCellEventArgs e)
{

dataGridView1.BackgroundImage = Image.FromFile(imagepath);
}

Yes you can

implement the cell

private void dataGridView1_CellClick(object sender,
DataGridViewCellEventArgs e)
{

dataGridView1.BackgroundImage = Image.FromFile(imagepath);
}

hi, i want to set backgroundimage to selected cell not grid backgroundimage

yes you can, and with a small amount of imagination it was very obvious and very simple. In fact MSDN shows almost how to do it, it shows how you draw something for a given cell and it took me like 2 minutes of my life which I bothered to do.

And you guys wonder why I get narked? Tiny amount of reading of msdn.

where b is a bitmap loaded in or such.

e.PaintContent(e.CellBounds);
            if (dataGridView1.CurrentCell.RowIndex == e.RowIndex && dataGridView1.CurrentCell.ColumnIndex == e.ColumnIndex)
            {
                e.Graphics.DrawImage(b, e.CellBounds);
            }
            else
            {
                e.PaintBackground(e.CellBounds, true);
            }
            e.Handled = true;

hi Lizr, thnks for reply. in which event i have to specify cellclick or in paint or cellpainting event. can u tel me

yes you can, and with a small amount of imagination it was very obvious and very simple. In fact MSDN shows almost how to do it, it shows how you draw something for a given cell and it took me like 2 minutes of my life which I bothered to do.

And you guys wonder why I get narked? Tiny amount of reading of msdn.

where b is a bitmap loaded in or such.

e.PaintContent(e.CellBounds);
            if (dataGridView1.CurrentCell.RowIndex == e.RowIndex && dataGridView1.CurrentCell.ColumnIndex == e.ColumnIndex)
            {
                e.Graphics.DrawImage(b, e.CellBounds);
            }
            else
            {
                e.PaintBackground(e.CellBounds, true);
            }
            e.Handled = true;

i want to c the content as wel as img. but the image s overlapping the cell content. how to c both .is it possible.plz tel me

I just noticed it pasted it funny.

That drawcontents should be just before the handled line not the first. Otherwise yes the background ovewrites it but you would have noticed that..

ya the image s overlapping in cellpainting event ,so if i added before the image , im drawing the string means each and every time the cellpainting event s firing whenever mouse enters to the grid.so the problwm s lot of records s available in grid. every time its drawing text based on clicked content.any more suggestion.

when you say its overlapping - what exactly is it overlapping? do you even mean overlapping? Please explain more clearly your issue as at the moment its not clear at all. If necessary, draw a picture or take a screen shot or something and use pointers and point out what you're getting you're not expecting.

the code I gave will only draw the picture for the current cell,and do normal behavor for all others, so I dont understand what the rest of your post is on about..

Please explain more fully and also explain what you've done to try and fix it.

This article has been dead for over six months. Start a new discussion instead.