We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

ButtonEdit GridControl cell type

Thread ID:

Created:

Updated:

Platform:

Replies:

120486 Sep 20,2015 01:20 PM Sep 23,2015 07:27 AM Windows Forms 3
loading
Tags: GridControl
tttmack
Asked On September 20, 2015 01:20 PM

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!

Adhikesevan Kothandaraman [Syncfusion]
Replied On September 21, 2015 05:21 AM

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


tttmack
Replied On September 22, 2015 12:03 AM

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

Adhikesevan Kothandaraman [Syncfusion]
Replied On September 23, 2015 07:27 AM

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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;