| |

VerySource

 Forgot password?
 Register
Search
View: 897|Reply: 4

How to change the color of a column and the color of a row in DATAGRID

[Copy link]

3

Threads

15

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-12-17 01:00:02
| Show all posts |Read mode
I want to change the color of the 2 columns in the DataGrid according to the conditions (for example, n> 0 all change colors), the data types of the two columns are both int type, please give me some advice
Reply

Use magic Report

1

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-12-17 16:00:01
| Show all posts
itemStyle
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-12-17 23:45:01
| Show all posts
foreach (DataGridItem dg in DataGrid1.Items)
{
  if (dg.ItemType==ListItemType.Item || dg.ItemType==ListItemType.AlternatingItem)
    {
         if(Convert.ToInt32( dg.Cells[0].Text)>0)
{
dg.Cells[0].ForeColor=Color.Red;
}
    }
}
Reply

Use magic Report

3

Threads

15

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

 Author| Post time: 2020-12-18 00:00:01
| Show all posts
What is the di in if(Convert.ToInt32(di.Cells[0].Text)>0)?
Reply

Use magic Report

1

Threads

18

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-12-18 12:00:01
| Show all posts
It's in foreach (DataGridItem dg in DataGrid1.Items).
It is an item, that is, a line.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list