Having an issue with DataGridViewButtonColumn

demausdauth

Well-known member
Joined
Mar 24, 2008
Messages
281
Location
Minnesota
Programming Experience
3-5
I have a datatable that I am using as a datasource to a datagridview. I am adding a datagridviewbuttoncolumn just before I set the datasource.
The problem that I am having is that I want the text "View" to show on the button and it is not.
I was under the impression that setting the Text property of the buttoncolumn would do so, but haven't had any luck.

I have tried adding the button column before setting the datasource, after the datasource, and I have added the button column in the designer. All of these have given me a column with no text on the button. Did I miss something. I have include the designer for the datagridview to help.

VB.NET:
'get current row NotesRefID
                        Dim AttTableNameToGet As String = dgvEmail.Rows(intDgvLastRow).Cells("NotesRefID").Value.ToString
                        dtAttachments = dsAttachments.Tables(AttTableNameToGet)

                        dgvAttachments.Font = New Font("Times New Roman", 10, FontStyle.Regular, GraphicsUnit.Pixel)

                        'add a column for a view button
                        Dim ViewButtonColumn As New DataGridViewButtonColumn()
                        ViewButtonColumn.Name = "ViewAttachment"
                        ViewButtonColumn.Text = "View"
                      
                        ' set the attachemtns datagrid view datasource
                        'dgvAttachments.Columns.Add(ViewButtonColumn)
                        dgvAttachments.DataSource = dtAttachments
                        dgvAttachments.Columns.Add(ViewButtonColumn)

                        'set widths on columns
                        dgvAttachments.Columns("Selected").Width = 30
                        dgvAttachments.Columns("FileName").Width = 125
                        dgvAttachments.Columns("ViewAttachment").Width = 50

                        'AttCount isn't visible
                        dgvAttachments.Columns("AttCount").Visible = False

                        'set the selected index of the datagrid
                        For Each dr As DataGridViewRow In dgvAttachments.Rows
                            dr.Selected = False
                        Next

Designer of the datagridview
VB.NET:
 'dgvAttachments
        '
        Me.dgvAttachments.AllowUserToAddRows = False
        Me.dgvAttachments.AllowUserToDeleteRows = False
        Me.dgvAttachments.AllowUserToResizeColumns = False
        Me.dgvAttachments.AllowUserToResizeRows = False
        Me.dgvAttachments.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.Disable
        Me.dgvAttachments.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing
        Me.dgvAttachments.ColumnHeadersVisible = False
        Me.dgvAttachments.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.colButton})
        Me.dgvAttachments.Location = New System.Drawing.Point(842, 328)
        Me.dgvAttachments.MultiSelect = False
        Me.dgvAttachments.Name = "dgvAttachments"
        Me.dgvAttachments.RowHeadersVisible = False
        Me.dgvAttachments.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing
        Me.dgvAttachments.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect
        Me.dgvAttachments.Size = New System.Drawing.Size(240, 150)
        Me.dgvAttachments.TabIndex = 14
 
UseColumnTextForButtonValue property :) (I know it sounds stupid, it is more obvious when you set up the column in Designer.)
 
Back
Top