GST Billing Software

header image

How to add a column with buttons in a DataGrid

Erachana Line

63. How to add a column with buttons in a DataGrid? How to write code for the button click event of that button?

A column with buttons in a DataGrid is useful when you need to open a particular record by clicking a button on DataGrid row.

To add a column, select the grid, Properties Tab, inMisc. Section, in Columns Property, click Collections. Click Add to add a new column.

If you want to add a button for existing column, select the particular column, in Column Property Section, select Property as a button.

Write a function in Expressions and associate it to ' CellClick' event.

The example code is as follows -

try

{

if (dgr_Data.Rows.Count > 0)

{

int col = dgr_Data.CurrentCell.ColumnIndex;

int rw = dgr_Data.CurrentCell.RowIndex;

dgr_Data.Rows[rw].Cells[dgr_DataColumnend_date.Name].Value = DBNull.Value;

}

}

catch (Exception exc)

{

MessageBox.Show("Unexpected error occured!" + Environment.NewLine + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

}