User clicking in Windows Forms DataBoundGrid

27 May 20211 minute to read

This page explains How to Use PushButton in a Column and Catch the User Clicking it and more details.

How to Use PushButton in a Column and Catch the User Clicking it

Set the CellType property in column style to “PushButton” and handle grids CellButtonClicked event. Use Description property of the column style to specify the text that is displayed on the button. To access a column’s style, use either GridDataBoundGrid.GridBoundColumns or GridDataBoundGrid.Binder.InternalColumn depending upon whether you have explicitly added the GridBoundColumns or not.

GridStyleInfo style = gridDataBoundGrid1.GridBoundColumns[1].StyleInfo;
style.CellType = "PushButton";
style.Description = "Push Me!";
gridDataBoundGrid1.CellButtonClicked += new GridCellButtonClickedEventHandler(grid_CellButtonClicked);

private void grid_CellButtonClicked(object sender, GridCellButtonClickedEventArgs e)
   string s = string.Format("You clicked ({0},{1}).", e.RowIndex, e.ColIndex);

Dim style As GridStyleInfo = gridDataBoundGrid1.GridBoundColumns(1).StyleInfo
style.CellType = "PushButton" 
style.Description = "Push Me!"
AddHandler gridDataBoundGrid1.CellButtonClicked, AddressOf grid_CellButtonClicked

Private Sub grid_CellButtonClicked(sender As Object, e As GridCellButtonClickedEventArgs)
Dim s As String = String.Format("You clicked ({0},{1}).", e.RowIndex, e.ColIndex)

End Sub