Change color of the Cell

Asked

Viewed 623 times

2

I need to change the color of the cell:

I’m doing it this way

 dataGridView.Rows[rowIndex].Cells["nomeDaColuna"].Style.BackColor = Color.Yellow;

however I can’t get past the rowIndex I would have to pass the "line name"

  • Lines don’t have names. Why do you need it that way? I’m pretty sure you don’t need something that doesn’t exist.

  • I believe that the best way to do this would be to check the value of a field of your line and according to the value of the field set its color.

1 answer

0


  1. You could explain what you want to do and what outcome you want to achieve?
  2. What do you mean by "line name" and why does it have to be the "line name"?

Thus, there are no names for the lines of grids in Datagridview as far as I know, but you can create a dictionary for this, which will take a lot of work, so I think it’s best to think about what you want to achieve at the end before and plan a little bit.

dataGridView.Rows[0].HeaderCell.Value = "NomeDaLinha1";
dataGridView.Rows["NomeDaLinha1"].DefaultCellStyle.BackColor = Color.Yellow;

It would be something like this, but you would have to specify the names of each line.

Attention: the above code has not been tested.

  • It is a limitation of the site that is sometimes a little annoying even. Anyway, I flagged your post as comment, I suggest you do the same, so a moderator will move to the comments.

  • @Diegofelipe Unfortunately the answers are not moved to comments, even if it is written there when signaling.

  • @jbueno for me then, I would leave as an answer, since it is an attempt to answer the question, although this lacks the information cited.

  • How do I signal as a comment?

  • I voted to remove, but I think if I keep just the part that is trying to "answer" it WILL BE totally valid.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.