Datagridview button color

DC123

New member
Joined
Jun 13, 2007
Messages
3
Programming Experience
Beginner
Hi,

I am trying to add rows containing a button to a Datagridrow control and would like the button to be red. When I use the code below the button does not turn red but the cell containing the button does. How can I turn the button red? Thanks.

VB.NET:
Private Sub AddRow(ByVal Product As String, ByVal Stock As String)     
 
        Dim NewRow As DataGridViewRow = New DataGridViewRow
        Dim CellButton As DataGridViewCell
 
        CellButton = New DataGridViewButtonCell
        CellButton.Value = Stock
        CellButton.Style.BackColor = Color.Red
        NewRow.Cells.Add(CellButton)
 
        DataGridView1.Rows.Add(NewRow)
 
        DataGridView1.AutoResizeColumns()
 
End Sub
 
This isn't as easy as it would appear, normally you could just turn off UseVisualStyleBackcolor for the button. However in a DgvButton column there are no Button controls, they are all painted based on the style information set. When FlatStyle is Standard/System the visual styles is applied. So you can choose to set FlatStyle to Popup/Flat or do CellPainting where you paint it all yourself, or perhaps internet search other solutions available (I haven't checked).
 
I had the same problem. I know this is an old thread, but I thought I'd post the solution I found to this. Change the FlatSysle of the button column to Popup. The button doesn't look as nice, IMO, but the problem is fixed.
 
JohnH said:
So you can choose to set FlatStyle to Popup/Flat
BenH said:
the solution I found to this. Change the FlatSysle of the button column to Popup.
Your welcome ;)
 
Back
Top