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

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #17049 |

    I need to implement row deletion feature, I need to put a image masked button on each 5th row of a cell.  Upon click it should take the first cell value(id) and call for deletion of that record.

    Couldn’t find a good solution on KB or help.

     

     

    Imported from legacy forums. Posted by bdmsoft (had 3420 views)

    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)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.