Click here to Skip to main content
12,451,425 members (47,940 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
in datagridview i have 24 rows is always constant one.

for that i want to set fore and back color for two, two rows i want set fore and back color in datagridview.

for example in datagridview as follows;

Date      session    RK     Mk      CK    GS   SJ
 
1/7/2013    1        REO    Tasco   PH2   AFF  TFc
1/7/2013    2        Tasco  ECDIs   ARPA  TFc  TFc
1/7/2013    3        PH2    ARPA    TFc   TFc  AFF
1/7/2013    4        TFc    AFF     AFF   TFc  AFF

i want to set fore and back color for session 1 and 2 in one fore and back color.


for session 3 and 4 in another fore and back color to be set.


using switch case.

how can i do.

Important note:in datagridview 24 rows is always be a constant one.
Posted 3-Feb-13 21:37pm
Updated 3-Feb-13 21:49pm
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

In your gridview's RowDataBound event you can do this.

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
   switch(e.Row.Cells[indexoftheSession].Text)
   {
     case "1":
     case "2":
          e.Row.BackColor = Color.Red;
          e.Row.ForeColor = Color.Red; 
          break;
     case "3":
     case "4":
          e.Row.BackColor = Color.Yellow;
          e.Row.ForeColor = Color.Yellow; 
          break;
   }
}
Good luck,
OI
  Permalink  
Comments
Member 8054539 4-Feb-13 4:27am
   
you send the code ok, But the above code will work out in windows application.

switch(e.Row.Cells[indexoftheSession].Text)

after cells you specify the indexofthesession,whether the above word,will work out in windows application.

i want to set fore and back color for windows application;


Date session RK Mk CK GS SJ

1/7/2013 1 REO Tasco PH2 AFF TFc
1/7/2013 2 Tasco ECDIs ARPA TFc TFc
1/7/2013 3 PH2 ARPA TFc TFc AFF
1/7/2013 4 TFc AFF AFF TFc AFF

Date session RK Mk CK GS SJ

1/8/2013 1 PH2 Tasco PH2 AFF TFc
1/8/2013 2 Tasco ECDIs ARPA PH2 TFc
1/8/2013 3 PH2 ARPA TFc TFc AFF
1/87/2013 4 TFc AFF AFF TFc AFF

i want to set the fore color and back ground color for each date and session wise.

example as follows;


1/7/2013 1 REO Tasco PH2 AFF TFc
1/7/2013 2 Tasco ECDIs ARPA TFc TFc

the above date 1/7/2013 for 1 and 2 session set forecolor and background color.


1/7/2013 3 PH2 ARPA TFc TFc AFF
1/7/2013 4 TFc AFF AFF TFc AFF

the above date 1/7/2013 for 3 and 4 session set forecolor and background color.



1/8/2013 1 PH2 Tasco PH2 AFF TFc
1/8/2013 2 Tasco ECDIs ARPA PH2 TFc

for the above 1/8/2013 set fore and back color for 1 and 2 session.

1/8/2013 3 PH2 ARPA TFc TFc AFF
1/8/2013 4 TFc AFF AFF TFc AFF

for the above 1/8/2013 set fore and back color for 3and 4 session.

for the above two dates i specified and also for session set fore and back color.

it is a windows appplication.

how can i do using switch case.
help me.

Thanks & regards,
narasiman P.
Orcun Iyigun 4-Feb-13 4:37am
   
Well if thats the case,then use the DataBindingComplete event in WinForms. I will not rewrite the code have a look at the following link[^] and modify it please.
Member 8054539 4-Feb-13 5:15am
   
for the above i sent already for that please send the code.help me.

i don't know.

kindly please send the code and help me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 4 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100