Articles in this section
Category / Section

How to set folder browser cell type in WinForms GridControl?

1 min read

Folder browser cell type

To use the FolderBrowser cell type, create custom FolderBrowserCellModel and FolderBrowserCellRenderer derived from GridTextBoxCellModel and GridTextBoxCellRenderer. The Folder Browser dialog box will be displayed in the OnButtonClicked event.

Creating CustomCellModel

C#

//Deriving  GridTextBoxCellModel. 
public class FolderBrowserCellModel : GridTextBoxCellModel
{
    protected FolderBrowserCellModel(SerializationInfo info, StreamingContext context)
        : base(info, context)
    {
        //Set the button bar size.
        base.ButtonBarSize = new Size(20, 20);
        
    }
    //Constructor for the Derived Class
    public FolderBrowserCellModel(GridModel grid)
        : base(grid)
    { 
 
    }
    //Override the CreateRenderer() in the Base class.
    public override GridCellRendererBase CreateRenderer(GridControlBase control)
    {
        //Return the Custom Renderer Object
        return new FolderBrowserCellRenderer(control, this);
    }
}

 

Creating CustomCellRenderer

//Deriving the GridTextBoxCellRenderer.
public class FolderBrowserCellRenderer : GridTextBoxCellRenderer
{
    //FolderBrowser object declaration.
    private System.Windows.Forms.OpenFileDialog folderBrowser1;
    public FolderBrowserCellRenderer(GridControlBase grid, GridTextBoxCellModel cellModel)
        : base(grid, cellModel)
    {
        AddButton(new BrowseButton(this));
 
        //Initialize the folderBrowser1 object.
        this.folderBrowser1 = new System.Windows.Forms.OpenFileDialog();
    }
    #region [overrides]        
    protected override void OnButtonClicked(int rowIndex, int colIndex, int button)
    {
        base.OnButtonClicked(rowIndex, colIndex, button);
        if(folderBrowser1.ShowDialog()== DialogResult.OK)
       {
            string filePath = folderBrowser1.FileName;     
       }         
    }    
}

 

Adding CellModel

// Add the custom cell type to the CellModels of the GridControl.
this.gridControl1.CellModels.Add("FolderBrowser", new FolderBrowserCellModel(gridControl1.Model));
 
// Set the cell type to "FolderBrowser"
this.gridControl1[2, 3].Text = "Browse here";
this.gridControl1[2, 3].CellType = "FolderBrowser";

 

Samples: FolderBrowser celltype in grid

 

Conclusion

I hope you enjoyed learning about how to set folder browser cell type in WinForms GridControl.

You can refer to our  WinForms GridControl feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridControl documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied