Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Datagridview cell formatting
Message
De
12/06/2010 19:18:19
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
12/06/2010 07:04:30
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:
01468691
Vues:
40
Your welcome. Sorry about the round about way of figureing it out.
Tim

>That did it!
>
>Thanks, Tim
>
>
>>>
>Ah, I guess I didn't think of that. How about this?
>
>this.dataGridViewTrackingSearch.Rows[e.RowIndex].Cells["ColumnSono"].Style.BackColor = Color.Blue;
>
>>Thanks but not quite, Tim
>>
>>It only work for the first row in the grid.
>>
>>I think that's because the CurrentRow property refers to the currently selected row, not the row currently being formattted.
>>
>>There has to be some way of looking at the data in other other columns of the row being formatted by doing something with the e. object, but I can't figure out how.
>>
>>
>>
>>
>>Bill,
>>
>>Now that I understand your question, I woudl think you can reference the other cell and set those same values with these right in the code you have.
>>
>>this.dataGridViewTrackingSearch.CurrentRow.Cells["ColumnSono"].Style.BackColor = Color.Blue;
>>this.dataGridViewTrackingSearch.CurrentRow.Cells["ColumnSono"].Style.SelectionBackColor = Color.Aqua;
>>
>>Tim
>>
>>>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
>>>
>>
>>T. Grant Bryan
>
>T. Grant Bryan
>BT Systems
Timothy Bryan
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform