---
title: "How to access a button in a grid control Programmically DevExpress?"  
description: "How to access a button in a grid control Programmically DevExpress?"  
author: "Anonymous User"  
published: 2014-11-19  
updated: 2014-11-20  
canonical: https://www.mindstick.com/forum/12646/how-to-access-a-button-in-a-grid-control-programmically-devexpress  
category: "asp.net"  
tags: ["devexpress"]  
reading_time: 2 minutes  

---

# How to access a button in a grid control Programmically DevExpress?

I wanna enable/[disable](https://www.mindstick.com/forum/12901/how-to-disable-enable-input-box-in-aspx-with-value-from-sql) a [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) found in every [row](https://www.mindstick.com/forum/1212/this-row-already-belongs-to-this-table) of my [grid](https://www.mindstick.com/forum/369/how-can-i-add-a-column-name-to-my-grid) control. I am not sure how I can [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) it through code. I would think it would bein the GridView1 methods.

## Replies

### Reply by Anonymous User

You can disable the button (or better yet, the entire editing of a specif cell) by just handling the ShowingEditor event... You can then inspect the values of other columns and then cancel the editing of that cell depending on your wishes. Here goes some code for a sample program that shows you exactly how to do that:

```
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using DevExpress.XtraGrid.Views.Grid;using DevExpress.XtraGrid;namespace GridButtonDisable{public partial class Form1 : Form{    public class MyData    {        public int Number { get; set; }        public bool Even { get { return Number % 2 == 0; } }    }    public Form1()    {        InitializeComponent();        List<MyData> List = new List<MyData>        {            new MyData() { Number = 1 },            new MyData() { Number = 2 },            new MyData() { Number = 5 },            new MyData() { Number = 7 },            new MyData() { Number = 10 },        };        gridControl1.DataSource = List;        gridView1.ShowingEditor += gridView1_ShowingEditor;    }    private void gridView1_ShowingEditor(object sender, CancelEventArgs e)    {        GridView view = sender as GridView;        if (view.FocusedColumn.Name == "gridButtonCol" &&             !(bool)view.GetRowCellValue(view.FocusedRowHandle, "Even") )            e.Cancel = true;    }}
```

This is a pretty simple program. You must assume your button edit column is named gridButtonCol... I'm testing the value of the Even column of the MyData class I've created for this sample, you can do whatever you want and check whichever condition you like here.

If you set the e.Cancel property of the CancelEventArgs of the ShowingEditor event, the cell won't be editable and the button editor won't respond to user clicks.


---

Original Source: https://www.mindstick.com/forum/12646/how-to-access-a-button-in-a-grid-control-programmically-devexpress

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
