Home Forums WinForms controls Xceed Grid for WinForms How to add a Command Button to grid cell Reply To: How to add a Command Button to grid cell

User (Old forums)
Member
Post count: 23064

Hi Buddhi,

the following code would do the job.  However, it takes for granted that you have an Xceed grid for .Net accessible (default name) on a form (default name), that you have a column named “column5” in that grid plus at least another column to be able to add rows and that you have an insertion row.  Of course, it also supposes that you have the right references to the namespaces you are refering to.

using System;
using System.Windows.Forms;
using Xceed.Grid;
using Xceed.Grid.Editors;
using Xceed.Grid.Viewers;
using Xceed.Editors;

namespace ButtonInACell
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      Xceed.Grid.Licenser.LicenseKey = “(your license key)”;  // if it’s not in your registry
      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      WinButton saveBtn = new WinButton(“Remove”);
      saveBtn.ButtonType = new ButtonType(ButtonBackgroundImageType.SpinUp, ButtonImageType.SpinUp);
      gridControl1.Columns[“column5”].CellEditorManager = new CellEditorManager(saveBtn, “”, true, true);
      gridControl1.Columns[“column5”].CellViewerManager = new CellViewerManager(saveBtn, “”);

      gridControl1.Columns[“column5”].ReadOnly = true;
      gridControl1.DataRowTemplate.Cells[“column5”].Click += new EventHandler(Cell_Click);
    }

    void Cell_Click(object sender, EventArgs e)
    {
      Xceed.Grid.DataCell cell = sender as Xceed.Grid.DataCell;
      if (cell != null)
      {
        MessageBox.Show(“Sending ” + cell.ParentRow.Cells[0].Value.ToString() + ” somewhere else…”);
        cell.ParentRow.Remove();
      }
    }
  }
}

 

Imported from legacy forums. Posted by Ghislain (had 1988 views)