Vote count:
0
So I have a dataGridView and I want to be able to select a cell and change its color. This is a homework assignment in which we are required to use a ColorDialog. I have a button at the top that brings up a ColorDialog to choose from, and I have been able to successfully change a cell's background color using this, but only a specific cell (just tested out (2,2)). I want it to only change the color of the cell selected. How do I let the ColorDialog know which cell is currently selected? My current code for clicking the actual button is this:
private void changeBGColorToolStripMenuItem_Click(object sender, EventArgs e)
{
ColorDialog cd = new ColorDialog();
cd.ShowDialog();
dataGridView1.Rows[2].Cells[2].Style.BackColor = cd.Color;
}
Like I said before I tested out (2,2) just to get it to work, and it does change that specific cell. I just want to know how to let this function know WHICH cell I actually have selected (or whether I have a cell selected at all!). I also have a CellBeginEdit and CellEndEdit functions if that helps. Thank you!
Aucun commentaire:
Enregistrer un commentaire