• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

how to change the color of a button cell in a data grid view

hi -- i've added a data grid view with datagridviewbuttomcolumns (code below).
foreach (string item in uc.ChannelNames)
                {
                    DataGridViewButtonColumn butcol = new DataGridViewButtonColumn();
                       profilerBottom_GV.Columns.Add(butcol);
                    butcol.Name = item;
                    profilerBottom_GV.Columns[item].Width = 62;
                 }
which works just fine. I can also click on the appropriate cell and go to the event handler. however, I want to access the properties of the button to change the background color of the button. There is a type called DataGridViewButtonCell which I assume has the necessary properties. I can't figure out how to create and link the DGVButtonCell instance to the appropriate cell so that i can access it in the event handler.
thanks.
0
jdcoburn
Asked:
jdcoburn
  • 2
1 Solution
 
aherpsCommented:
Hi jdcoburn,

You would do something like:
foreach (string item in uc.ChannelNames)
                {
                    DataGridViewButtonColumn butcol = new DataGridViewButtonColumn();
                    butcol.Name = item;
                    butcol.CellTemplate.Style.ForeColor = Color.FromArgb(255, 0, 0);
                    profilerBottom_GV.Columns.Add(butcol);
                    profilerBottom_GV.Columns[item].Width = 62;
                 }

Open in new window

0
 
aherpsCommented:
Apologies - utcol.CellTemplate.Style.BackColor = Color.FromArgb(255, 0, 0);
0
 
jdcoburnAuthor Commented:
hi -- thanks for the reply. my problem is i'm creating a series of button columns (1 -n) with the foreach loop. I want to address a specific button [row, column] and the cell template seems to be global to all the button columns i've added.
Jim
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now