ButtonEdit GridControl cell type

Hello,

I am looking to see if there is any way that I can have a combo-box and a button in the same single cell in a GridControl. I would like to have a combo-box on the left side of the cell and a small button on the right side of the cell.

So basically I am looking to have something like the ButtonEdit control, but within a GridControl cell shared with a ComboBox.

Is something like this possible to do?

Thanks for your help!

3 Replies

AK Adhikesevan Kothandaraman Syncfusion Team September 21, 2015 09:21 AM UTC

Hi Taylour,

Thanks for contacting Syncfusion Support.

To have a combination of ComboBox and the ButtonEdit cell within a single Grid cell, create a custom cell model and renderer which is derived from the ComboBoxCellModel and renderer. Please refer to the following code example,

Code Example:
//Custom cellModel and Renderer

class ComboCellModel : GridComboBoxCellModel

{

    public ComboCellModel(GridModel grid)

        : base(grid)

    {

        //Set the size of the button bar.

        ButtonBarSize = new System.Drawing.Size(30, 15);

    }

    public override GridCellRendererBase CreateRenderer(GridControlBase control)

    {

        return new ComboCellRenderer(control, this);

    }

}


class ComboCellRenderer : GridComboBoxCellRenderer

{

    GridCellButton button;

    public ComboCellRenderer(GridControlBase control, GridCellModelBase model)

        : base(control, model)

    {

        button = new GridCellButton(this);

        //Add the button to the comboBox cell

        this.AddButton(button);

    }
}

//In FormLoad

//Register the custom CellModel

this.gridControl1.Model.CellModels.Add("ComboBoxButtonEditCell", new ComboCellModel(this.gridControl1.Model));

//Setting the CellType
this.gridControl1[2, 3].CellType = "ComboBoxButtonEditCell";

Sample:  http://www.syncfusion.com/downloads/support/forum/120486/ze/CS1040098417

Also, refer to the following dashboard sample, which shows how to have the custom cell types in the GridControl.

Dashboard Sample Location:

<InstalledLocation>\Syncfusion\EssentialStudio\<VersionNo>\Windows\Grid.Windows\Samples\Custom Cell Types\Interactive Cell Demo\CS


Regards,
Adhi



TT tttmack September 22, 2015 04:03 AM UTC

thanks for your help Adhi.

I am having trouble figuring out how to add a button click event to the button. I'd like the button with the down arrow to expand the combobox and the rightmost button beside it to perform a separate action. By default both buttons seem to have the same event which is to expand the ComboBox.

I have tried something like this, but the IsPushed property never seems to be true.
void gridControl1_CellButtonClicked(object sender, GridCellButtonClickedEventArgs e)
{
            if (e.Button.IsPushed(e.RowIndex, e.ColIndex))
                MessageBox.Show(String.Format("Pressed Button at ({0},{1})", e.RowIndex, e.ColIndex));
}

I have also tried some code like this, but it just repeatedly calls the event in an endless loop when I click the rightmost button:
var renderer = gridControl1.GetCellRenderer(2, 3) as ComboCellRenderer;
renderer.Button.Clicked += MyButton_Clicked;

void MyButton_Clicked;(object sender, GridCellEventArgs e)
{
        MessageBox.Show(String.Format("Pressed Button at ({0},{1})", e.RowIndex, e.ColIndex));
}

Could you please show me the correct method of achieving this?

Thanks so much!
Taylour


AK Adhikesevan Kothandaraman Syncfusion Team September 23, 2015 11:27 AM UTC

Hi Taylour,

Thanks for your update.

It is working properly when we have invoked the button_Clicked event through the renderer. Please refer to the following code example,

Code Example:

//Get the ComboCellRenderer

ComboCellRenderer renderer = gridControl1.GetCellRenderer(2, 3) as ComboCellRenderer;

//Invoke the button clicked event
renderer.button.Clicked += button_Clicked;

void button_Clicked(object sender, GridCellEventArgs e)

{

    MessageBox.Show(String.Format("Pressed Button at ({0},{1})", e.RowIndex, e.ColIndex));
}

Sample: http://www.syncfusion.com/downloads/support/forum/120486/ze/ButtonClicked409237133

Regards,

Adhi


Loader.
Up arrow icon