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

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

0
sqdperu
Asked:
sqdperu
1 Solution
 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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