changing cell color datagridvew c#

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

Join Date: Nov 2007
Posts: 144
Reputation: emilio is an unknown quantity at this point 
Solved Threads: 0
emilio emilio is offline Offline
Junior Poster

changing cell color datagridvew c#

 
0
  #1
Dec 8th, 2008
hi
i'm using a datagrid view control which get's his datasource from a dataset control.

my code is:

  1. dataGrid = new DataGridView();
  2. dataGrid.DataSource = dataSet.Tables["Vertexes"];
  3. this.Controls.Add(dataGrid);

the datagridview in shown fine.
the problem is that when i try to cahnge cells color like this:

  1. for (int x = 0; x < dataGrid.Rows.Count; x++)
  2. {
  3. for (int y = 0; y < dataGrid.Rows[x].Cells.Count; y++)
  4. {
  5. if (x == y)
  6. {
  7. dataGrid.Rows[x].Cells[y].Style.BackColor =
  8. System.Drawing.Color.Red;
  9. }
  10. }
  11. }

it doest eners to the 'for' loop. i can see in debug that the datagridvew rows and columns controls are empty.
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: changing cell color datagridvew c#

 
0
  #2
Dec 8th, 2008
Depends I guess a little on when that code runs (which you havent shown) or, why you dont just use the draw method - for which search this forum ther are a number of examples
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: 65
Reputation: Renukavani is an unknown quantity at this point 
Solved Threads: 6
Renukavani Renukavani is offline Offline
Junior Poster in Training

Re: changing cell color datagridvew c#

 
0
  #3
Dec 9th, 2008
hi
this s my code working fine. i think r u creating dynamic datagridview . insead of controlname ur using datagrid may be. so chk it
private void Form1_Load(object sender, EventArgs e)
{

dataGridView1.Rows.Add(5);
dataGridView1.CurrentCell.Selected = false;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
for (int j = 0; j < dataGridView1.Rows[i].Cells.Count; j++)//dataGridView1.Columns.Count; j++)
{
// dataGridView1.Rows[i].Cells[j].Value = i + 5;
if (i == j)
dataGridView1.Rows[i].Cells[j].Style.BackColor = Color.Aqua;
}
}
}
signOut
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 32
Reputation: reena12 is an unknown quantity at this point 
Solved Threads: 4
reena12 reena12 is offline Offline
Light Poster

Re: changing cell color datagridvew c#

 
0
  #4
Dec 9th, 2008
Hi,

dataGrid.DataBind() statement is missing.

dataGrid = new DataGridView();
this.Controls.Add(dataGrid);

dataGrid.DataSource = dataSet.Tables["Vertexes"];
dataGrid.DataBind();
Reena Mehta

Remember to click on Mark as answer on the post that helped

http://www.indianic.com
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
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC