| | |
changing cell color datagridvew c#
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2007
Posts: 144
Reputation:
Solved Threads: 0
hi
i'm using a datagrid view control which get's his datasource from a dataset control.
my code is:
the datagridview in shown fine.
the problem is that when i try to cahnge cells color like this:
it doest eners to the 'for' loop. i can see in debug that the datagridvew rows and columns controls are empty.
i'm using a datagrid view control which get's his datasource from a dataset control.
my code is:
c# Syntax (Toggle Plain Text)
dataGrid = new DataGridView(); dataGrid.DataSource = dataSet.Tables["Vertexes"]; this.Controls.Add(dataGrid);
the datagridview in shown fine.
the problem is that when i try to cahnge cells color like this:
c# Syntax (Toggle Plain Text)
for (int x = 0; x < dataGrid.Rows.Count; x++) { for (int y = 0; y < dataGrid.Rows[x].Cells.Count; y++) { if (x == y) { dataGrid.Rows[x].Cells[y].Style.BackColor = System.Drawing.Color.Red; } } }
it doest eners to the 'for' loop. i can see in debug that the datagridvew rows and columns controls are empty.
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
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.
•
•
Join Date: Jul 2008
Posts: 65
Reputation:
Solved Threads: 6
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
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
![]() |
Other Threads in the C# Forum
- Previous Thread: Return value failed in Invoke
- Next Thread: Need help Marshaling in C#...
| Thread Tools | Search this Thread |
.net 2007 access algorithm array barchart bitmap box broadcast c# camera check checkbox client combobox control conversion cs4 csharp custom customactions database datagrid datagridview dataset date datetime degrees development draganddrop drawing encryption enum event eventcloseformc# excel file form format forms function gdi+ handler httpwebrequest image index input install java keypress label list listbox listener listview load mandelbrot math mouseclick mysql operator path photoshop picturebox pixelinversion post programming radians regex remote remoting resolved. richtextbox search security server sleep socket sql statistics stream string table text textbox thread time timer update usercontrol validation view visual visualstudio webbrowser windows winforms wordautomation wpf xml






