[RESOLVED]DataGridViewButtonColumn problem
Hi all,
Is it possible to change during run time text displayed on one particular button which is placed in DataGridView colum. This column type is DataGridViewButtonColumn???
I was trying to do it like that:
VB Code:
Me.DataGridView1.CurrentRow.Cells(1).Value = "hello"
Me.DataGridView1.Refresh()
but without result.
Or is it possible to go through all buttons in this column and change it's text depending on for example variables value???
:mad: :confused: :sick:
Please help,
sweet_dreams
Re: DataGridViewButtonColumn problem
When would you want to change it ? When another cell in that row is edited ? Or some other event....
Bob
Re: DataGridViewButtonColumn problem
Quote:
Originally Posted by staticbob
When would you want to change it ? When another cell in that row is edited ? Or some other event....
Bob
I would like to change it when this button is pushed.
When it is pushed it fires function and when function returns True button text should change. When Function returns False, button text should remain the same.
sweet_dreams
Re: DataGridViewButtonColumn problem
This should work...
dataGridView(4,1).Value = "new button text"
Make sure you don't have the UseColumnTextForButtonValue property set to true. If you do, then you’ll need to set it to false for each cell before you set the cell’s value.
Bob
From here...
Re: DataGridViewButtonColumn problem
Where are you calling this function from when the buttons are clicked? It should be the CellContentClicked event handler. You can then simply set the Value of the CurrentCell based on the return value of the function you call, e.g.
VB Code:
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.ColumnIndex = Me.DataGridView1.Columns("Column2").Index Then
Me.DataGridView1.CurrentCell.Value = Me.IsEven(e.RowIndex).ToString()
End If
End Sub
Private Function IsEven(ByVal number As Integer) As Boolean
Return number Mod 2 = 0
End Function
Re: DataGridViewButtonColumn problem
Thanks jmcilhinney it works fine. Thanks one more time Buddy.
Sometimes I come to conclusion that you escaped from Redmond ;)
regards,
sweet_dreams