Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing a datagridview button's caption at runtime

Status
Not open for further replies.

JScannell

Programmer
Jan 9, 2001
306
US
I've got an unbound datagridview. At page load, I add a bunch of columns including 5 button columns. Here is the code I use to create the button:

Dim btnCA_Notes As New DataGridViewButtonColumn()
dgvInputRecords.Columns.Add(btnCA_Notes)
btnCA_Notes.HeaderText = "C. A. Notes"
btnCA_Notes.Text = "View"
btnCA_Notes.Name = "btnCA_Notes"
btnCA_Notes.UseColumnTextForButtonValue = True

At runtime, I perform a SQL lookup based on user inputs. If there is a CA Note in the database record, then clicking the button will allow the user to View it.

If, however, that column is empty, I want to change the button's Text property to say: "No Note". (What I actually would also want to do, is disable the button as well. But since I can't seem to figure out how to change the Text value, I have to assume that it would take a lot to make the button disabled...)

Someone in another post said that all you had to do was:
If reader(23).ToString = "" Then
dgvInputRecords.Rows(numRowCount - 1).Cells(23).Value = "NO Note"
dgvInputRecords.Rows(numRowCount - 1).Cells(23).Style.BackColor = Color.Red
Else
dgvInputRecords.Rows(numRowCount - 1).Cells(23).Value = "View"
dgvInputRecords.Rows(numRowCount - 1).Cells(23).Style.BackColor = Color.Black
End If


But that doesn't work at all.

Does anyone know how to alter the button's properties at runtime?

Thanks in advance,


Jerry Scannell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top