| | |
changing cell color datagridvew c#
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2007
Posts: 146
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: 66
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#...
Views: 1097 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access algorithm array barchart bitmap box button buttons c# chat check checkbox class client code color combobox control conversion csharp custom database datagridview dataset datetime degrees draganddrop drawing encryption enum excel file files form format forms ftp function gcd gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






