How do I hide DataGridView buttons only for certain cells and show the DataTable column value instead?

I am using VB.net 2005 and would like a sample that works for it. I have a loop that goes thru the DataGridView and changes the row color based on a column/cell value from a binded DataTable (code shown below). I'd like to add to the loop (where the comment is) and hide the button for this cell and let the "In Process" show in the cell instead. Is there a simple way to do this? Thanks.
   
Private Sub ColorInProcessItems()

        ' Color the rows green if they are In Process, red if they are Complete
        For Each row As DataGridViewRow In dgvQueue.Rows
            If Not row.IsNewRow Then
                If Not row.Cells(0).Value Is DBNull.Value Then
                    If row.Cells(7).Value.ToString = "In Process" Then
                        row.DefaultCellStyle.BackColor = Color.LimeGreen
                        '>>> Need code here to hide button and let "In Process" 
                        '    (the cells value from DataTable) show instead <<<
                    ElseIf row.Cells(7).Value.ToString = "Complete" Then
                        row.DefaultCellStyle.BackColor = Color.IndianRed
                    End If
                End If
                ' Color blank dividing lines
                If row.Cells(2).Value.ToString = "" Then
                    row.DefaultCellStyle.BackColor = Color.DimGray
                End If
            End If
        Next

    End Sub

Open in new window

sqdperuAsked:
Who is Participating?
 
sqdperuAuthor Commented:
I was able to achieve what I wanted by using this code:

http://msdn.microsoft.com/en-us/library/ms171619(v=VS.80).aspx

and tweaking my code to look like this:


Private Sub ColorInProcessItems()

        ' Color the rows green if they are In Process, red if they are Complete
        For Each row As DataGridViewRow In dgvQueue.Rows
            If Not row.IsNewRow Then
                If Not row.Cells(0).Value Is DBNull.Value Then
                    If row.Cells(7).Value.ToString = "In Process" Then
                        row.DefaultCellStyle.BackColor = Color.LimeGreen
                        '>>> Need code here to hide button and let "In Process" 
                        '    (the cells value from DataTable) show instead <<<
                        Dim buttonCell As DataGridViewDisableButtonCell = _
                                          CType(row.Cells("Status"), _
                                          DataGridViewDisableButtonCell)
                        buttonCell.Enabled = False
                        dgvQueue.Invalidate()
                    ElseIf row.Cells(7).Value.ToString = "Complete" Then
                        row.DefaultCellStyle.BackColor = Color.IndianRed
                    End If
                End If
                ' Color blank dividing lines
                If row.Cells(2).Value.ToString = "" Then
                    row.DefaultCellStyle.BackColor = Color.DimGray
                End If
            End If
        Next
   
    End Sub

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.