1

I am implementing a datagridview and a button on it using below code:

$Column2 = $TR = New-Object System.Windows.Forms.DataGridViewButtonColumn
$Column2.width = 150
$Column2.name = "App Data"
$Column2.FlatStyle = 'Standard'
$DataGridView1.Columns.Add($Column2)
$Column2.UseColumnTextForButtonValue = $true
$Column2.AutoSizeMode = 'DisplayedCells'
$TR.Text = "Change Data"

When I click another button (not the one implemented on grid), I need to change the text of button implemented on grid to something. For example, from "Change Data" to "Delete Data".

And also how do I implement Click event for button implemented on the grid.

Thanks heaps for your help! Nratawa

NickPrice
  • 45
  • 2
  • 9
  • To change the button column's text, grab the column, cast as a DataGridViewButtonColumn, then set the Text property - or if `$Column2` is available, `$Column2.Text = "Delete Data"`. For the click events of the column's buttons, handle the `DataGridView.CellContentClick` similar to [this C# answer](http://stackoverflow.com/a/7286587/3773066) but following the comment advice from Igor. – OhBeWise Aug 26 '15 at 21:51
  • Hi, This didn't work for me. I use below code in Button Click event to change the Column button text to designed one, to no avail: – NickPrice Aug 27 '15 at 11:25
  • $buttonChangeThis_Click={ $RemText = "Change Data" $datagridview1.Columns[2].DataGridViewButtonColumn.text = "$RemText" } – NickPrice Aug 27 '15 at 11:26
  • In the code attempt you've shown, you use the original `"Change Data"`. Did you try this with `"Delete Data"`? – OhBeWise Aug 27 '15 at 14:54
  • Hi - All I need to do is rename column button to something else when I click another button. In another button's Click Event, what is the code I need to put so it allows me to rename Column button's text from a variable. My application adds text to be renamed to a variable called $RemText. $RemText may contain "Change Data", "Delete Data", etc... Thanks. – NickPrice Aug 28 '15 at 03:00

0 Answers0