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.

How to add more than one button in a Grid Cell?

To set more than one button in a cell for particular column in grid and handled the click event for button. Here we have create a custom cell renderer classMultipleButtonGridCell”.

1. Creating CellModel/CellRenderer in a class

You can use the GridModel class to create the CellModel class in a grid. The GridModel class can hold all the information about the grid. Using “GridCellRendererBase” class to create the CellRenderer class in the CellModel class.

 

If you want to add TextBoxCellModel class, you can use the GridTextBoxCellModel class. Use the “TextBoxCellRendererBase” class to create the GridTextBoxCellRenderer class in the TextBoxCellModel class.

 

Refer the following code example for MultipleButtonCellModel.

C#

 

VB

 

Refer the following code example for MultipleButtonCellRender.

 

C#

 

VB

2. Adding CellModel into grid

If you want to add the Cellmodel class into grid, you can use the Add method of cellmodel collection. In the collection you can add the CellType and CellModel class name.

You can add the new CellType into CellModels through the following code examples.

 

C#

 

VB

 

3. Assigning the CellType

You can set the CellType in the grid and the assigned same CellType name in the CellModel collection.

Refer the following code example for assigning the CellType of a cell using QueryCellStyleInfo event.

 

C#

 

VB

4. Adding a Button and handle the click event

If you want to add the button into a cell, you can use the AddButton( ) method in the CellRenderer class. In our sample, we have added a normal button, here a class MultipleButtonGridCell is created that have the CustomCellmodel class (MultileButtonCellModel) and renderer class MultipleButtonCellRender. The MultileButtonCellModel class can define the size of the button in the model class by using “ButtonBarSize” property. The MultipleButtonCellRenderer class is used to add the number of buttons inside the cell.

 

The TableControlCellButtonClicked event is handled for each button of the cell and you can identify which button was clicked using e.Inner.Button attribute.

 

C#

 

VB

 

5. Adding an Image

If you want to add the image into a cell, you can use the AddButton( ) method in the CellRenderer class. In our sample, we have added an image, here a class MultipleImageCell is created that have the CustomCellmodel class (MultipleImageCellModel) and renderer class MultipleImageCellRenderer and using Draw( ) method to draw the image inside the button. The MultipleImageCellModel class can define the size of the button in the model class by using “ButtonBarSize” property. . The MultipleImageCellRenderer class is used to add the number of image inside the cell.

 

Refer the following code example for Draw( )

 

C#

 

VB

 

Refer the following code example for MultipleImageCellRenderer

C#

 

VB

 

 

Sample Link:

C#: MultipleButtonGridCell CS

VB: MultipleButtonGridCell VB               

 

Article ID: Published Date: Last Revised Date: Platform: Control:
3015 12/10/2014 02/13/2017 Windows Forms GridGroupingControl
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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.