Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Datagridview cell formatting
Message
 
 
À
11/06/2010 18:53:49
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01468613
Message ID:
01468626
Vues:
27
>Hi Bill,
>
>>The code below sets the backcolor of the ColumnHasComments column to Red if the source data table record has "Y" in the hascomment field.
>>That works fine.
>>How would I set the backcolor of another column (ColumnSono) to Red for the same condition (hascomment = "Y")
>>
>>
>>
>> private void dataGridViewTrackingSearch_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
>>     {
>>       if (dataGridViewTrackingSearch.Columns[e.ColumnIndex].Name.Equals("ColumnHasComment"))
>>       {
>>         if (e.Value != null)
>>         {
>>          
>>           if (e.Value.ToString() == "Y")
>>           {
>>             e.CellStyle.BackColor = Color.Red;
>>             e.CellStyle.SelectionBackColor = Color.DarkRed;
>>           }
>>         }
>>       } 
>>     } // end CellFormatting
>>
>
>I may not be understanding your question so I appologize ahead of time. I would think you could just do something such as this.
>
>private void grdMembers_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
>{
>     if (e.Value != null)
>     {
>          string colName = grdMembers.Columns[e.ColumnIndex].Name;
>          if (e.Value.ToString() == "Y")
>          {
>               switch (colName)
>               {
>                    case "ColumnHasComment":
>                         e.CellStyle.BackColor = Color.Red;
>                         e.CellStyle.SelectionBackColor = Color.DarkRed;
>                         break;
>                    case "ColumnSono" :
>                         e.CellStyle.BackColor = Color.Blue;
>                         e.CellStyle.SelectionBackColor = Color.Beige;
>                         break;
>               }
>          }
>     }
>}
>
>Tim

This is much cleaner code, but it still will check value of the currently selected column, not from the ColumnHasComment.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform