is it possible to set backgroundimage to selected cell

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2008
Posts: 66
Reputation: Renukavani is an unknown quantity at this point 
Solved Threads: 6
Renukavani Renukavani is offline Offline
Junior Poster in Training

is it possible to set backgroundimage to selected cell

 
0
  #1
Oct 31st, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 21
Reputation: viswa_007 is an unknown quantity at this point 
Solved Threads: 3
viswa_007's Avatar
viswa_007 viswa_007 is offline Offline
Newbie Poster

Re: is it possible to set backgroundimage to selected cell

 
0
  #2
Oct 31st, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 172
Reputation: Jugortha is an unknown quantity at this point 
Solved Threads: 16
Jugortha Jugortha is offline Offline
Junior Poster

Re: is it possible to set backgroundimage to selected cell

 
0
  #3
Nov 1st, 2008
Yes you can

implement the cell

private void dataGridView1_CellClick(object sender,
DataGridViewCellEventArgs e)
{

dataGridView1.BackgroundImage = Image.FromFile(imagepath);
}
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 66
Reputation: Renukavani is an unknown quantity at this point 
Solved Threads: 6
Renukavani Renukavani is offline Offline
Junior Poster in Training

Re: is it possible to set backgroundimage to selected cell

 
0
  #4
Nov 3rd, 2008
Originally Posted by Jugortha View Post
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: is it possible to set backgroundimage to selected cell

 
0
  #5
Nov 3rd, 2008
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.

  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.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 66
Reputation: Renukavani is an unknown quantity at this point 
Solved Threads: 6
Renukavani Renukavani is offline Offline
Junior Poster in Training

Re: is it possible to set backgroundimage to selected cell

 
0
  #6
Nov 3rd, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: is it possible to set backgroundimage to selected cell

 
0
  #7
Nov 3rd, 2008
Um

take a look at the events one kinda stands out.
Last edited by LizR; Nov 3rd, 2008 at 6:38 am.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 66
Reputation: Renukavani is an unknown quantity at this point 
Solved Threads: 6
Renukavani Renukavani is offline Offline
Junior Poster in Training

Re: is it possible to set backgroundimage to selected cell

 
0
  #8
Nov 3rd, 2008
Originally Posted by LizR View Post
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.

  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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: is it possible to set backgroundimage to selected cell

 
0
  #9
Nov 3rd, 2008
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..
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 66
Reputation: Renukavani is an unknown quantity at this point 
Solved Threads: 6
Renukavani Renukavani is offline Offline
Junior Poster in Training

Re: is it possible to set backgroundimage to selected cell

 
0
  #10
Nov 3rd, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum


Views: 1358 | Replies: 10
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC