943,902 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 2324
  • C# RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 31st, 2008
0

is it possible to set backgroundimage to selected cell

Expand Post »
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
Last edited by Renukavani; Oct 31st, 2008 at 2:30 am.
Reputation Points: 10
Solved Threads: 23
Junior Poster
Renukavani is offline Offline
123 posts
since Jul 2008
Oct 31st, 2008
0

Re: is it possible to set backgroundimage to selected cell

dataGridView1.Rows[Row].Cells[ColName].Style.SelectionBackColor =your color(Color.Red)

for image find this link:
http://msdn.microsoft.com/en-us/libr...nt(VS.80).aspx
Last edited by viswa_007; Oct 31st, 2008 at 7:16 am.
Reputation Points: 10
Solved Threads: 3
Newbie Poster
viswa_007 is offline Offline
23 posts
since Sep 2007
Nov 1st, 2008
0

Re: is it possible to set backgroundimage to selected cell

Yes you can

implement the cell

private void dataGridView1_CellClick(object sender,
DataGridViewCellEventArgs e)
{

dataGridView1.BackgroundImage = Image.FromFile(imagepath);
}
Reputation Points: 11
Solved Threads: 16
Junior Poster
Jugortha is offline Offline
172 posts
since Oct 2007
Nov 3rd, 2008
0

Re: is it possible to set backgroundimage to selected cell

Click to Expand / Collapse  Quote originally posted by Jugortha ...
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
Reputation Points: 10
Solved Threads: 23
Junior Poster
Renukavani is offline Offline
123 posts
since Jul 2008
Nov 3rd, 2008
0

Re: is it possible to set backgroundimage to selected cell

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.

C# Syntax (Toggle Plain Text)
  1.  
  2. e.PaintContent(e.CellBounds);
  3. if (dataGridView1.CurrentCell.RowIndex == e.RowIndex && dataGridView1.CurrentCell.ColumnIndex == e.ColumnIndex)
  4. {
  5. e.Graphics.DrawImage(b, e.CellBounds);
  6. }
  7. else
  8. {
  9. e.PaintBackground(e.CellBounds, true);
  10. }
  11. e.Handled = true;
Last edited by LizR; Nov 3rd, 2008 at 6:30 am.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Nov 3rd, 2008
0

Re: is it possible to set backgroundimage to selected cell

hi Lizr, thnks for reply. in which event i have to specify cellclick or in paint or cellpainting event. can u tel me
Last edited by Renukavani; Nov 3rd, 2008 at 6:37 am.
Reputation Points: 10
Solved Threads: 23
Junior Poster
Renukavani is offline Offline
123 posts
since Jul 2008
Nov 3rd, 2008
0

Re: is it possible to set backgroundimage to selected cell

Um

take a look at the events one kinda stands out.
Last edited by LizR; Nov 3rd, 2008 at 6:38 am.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Nov 3rd, 2008
0

Re: is it possible to set backgroundimage to selected cell

Click to Expand / Collapse  Quote originally posted by LizR ...
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.

C# Syntax (Toggle Plain Text)
  1.  
  2. e.PaintContent(e.CellBounds);
  3. if (dataGridView1.CurrentCell.RowIndex == e.RowIndex && dataGridView1.CurrentCell.ColumnIndex == e.ColumnIndex)
  4. {
  5. e.Graphics.DrawImage(b, e.CellBounds);
  6. }
  7. else
  8. {
  9. e.PaintBackground(e.CellBounds, true);
  10. }
  11. 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
Reputation Points: 10
Solved Threads: 23
Junior Poster
Renukavani is offline Offline
123 posts
since Jul 2008
Nov 3rd, 2008
0

Re: is it possible to set backgroundimage to selected cell

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..
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Nov 3rd, 2008
0

Re: is it possible to set backgroundimage to selected cell

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.
Reputation Points: 10
Solved Threads: 23
Junior Poster
Renukavani is offline Offline
123 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Looking for a project to join
Next Thread in C# Forum Timeline: print pdf file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC