Advertisement

12.05.2007 at 11:28AM PST, ID: 23004072
[x]
Attachment Details

VB.Net - datagridview buttoncell how to make button not visible conditionally

Asked by keningram in Microsoft Visual Basic.Net

Tags: datagridview, button, visible

I working on a VB.Net Windows Form application in VS 2008. It has a datagridview control with a DataGridViewButtonColumn.  I want the button to be visible in some cases and not visible in others. I tried the code below and it gives me an error stating that the Visible property is ReadOnly.  What am I doing wrong?

Thanks,
KenStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
Private Sub dgMessages_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles dgMessages.CellPainting
        If e.RowIndex > -1 Then
            If (dgMessages.Rows(e.RowIndex).Cells("Comment1").Value.Equals("")) And (e.ColumnIndex = 4) Then
                Dim buttonCell As DataGridViewButtonCell = CType(dgMessages.Rows(e.RowIndex).Cells("Comments"), DataGridViewButtonCell)
                buttonCell.Visible = False ' This is where I get the ReadOnly error
            End If
        End If
    End Sub
[+][-]12.13.2007 at 10:21AM PST, ID: 20466258

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual Basic.Net
Tags: datagridview, button, visible
Sign Up Now!
Solution Provided By: Masteraco
Participating Experts: 2
Solution Grade: A
 
 
[+][-]01.05.2008 at 04:01PM PST, ID: 20591737

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628