Ankit Raman
Ankit Raman

Reputation: 79

How to implement GridControl with CheckBox inside it in Syncfusion using C Sharp?

I want to implement GridControl for my project but I realize Syncfusion GridControl is little more tough than Windows controls. my requirement is like that: Suppose I have three columns and 15 rows in my gridControl and in first column of first row I want to write some hardcoded input string and in second column of first row I want to add CheckBox.
Kindly suggest me how to bind cells with CheckBox so that it would work dynamically while scrolling.

I also go through from Here:

Upvotes: 1

Views: 318

Answers (1)

Prithiv
Prithiv

Reputation: 514

Query 1

In first column of first row I want to write some hardcoded input string Suggestion 1

The cell value for a particular cell can be set by using CellValue property of cell style. Please refer the below code,

this.gridControl1[1, 1].CellValue = "Sample";

Suggestion 2

The cell value can also be set by using Text property of cell style. Please make use of below code,

this.gridControl1[2, 1].Text = "Data";

Suggestion 3

To set the cell value for a particular cell, the QueryCellInfo event can also be used. Please refer below code,

//Event Triggering
this.gridControl1.QueryCellInfo += GridControl_QueryCellInfo;
//Event Customization
private void GridControl_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
    if(e.RowIndex==1 && e.ColIndex==1)
    {
        e.Style.CellValue = "Sample Name";
    }

    if(e.RowIndex==2 && e.ColIndex==1)
    {
        e.Style.Text = "Sample ID";
    }
}

Query 2

In second column of first row I want to add Checkbox

Suggestion 1

To set the cell type as CheckBox for a particular cell, the CellType property can be used and the name for the CheckBox can be set by using Description property. Please refer the below code,

this.gridControl1[1, 2].CellType = GridCellTypeName.CheckBox;
this.gridControl1[1, 2].Description = "CheckBox";

The CheckBox can be checked or unchecked based on the cell value by defining the CheckBoxOptions property of the cell.

this.gridControl1[1, 2].CheckBoxOptions =  new GridCheckBoxCellInfo("True","False","False",true);
this.gridControl1[1, 2].CellValue = "True";

Suggestion 2

To set Cell type as CheckBox for a particular cell, the QueryCellInfo event can also be used. Please refer the below code,

//Event Triggering
this.gridControl1.QueryCellInfo += GridControl_QueryCellInfo;
//Event Customization
private void GridControl_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
    if(e.RowIndex==2 && e.ColIndex==2)
    {
        e.Style.CellType = GridCellTypeName.CheckBox;
        e.Style.Description = "CheckBox";
        e.Style.CheckBoxOptions.CheckedValue = "True";
        e.Style.CellValue="True";
    }
}

Screenshot

Sample Link

UG Link

Dashboard sample

\Syncfusion\EssentialStudio<Installed Version>\Windows\Grid.Windows\Samples\ Cell Types\Interactive Cell Demo\CS

Upvotes: 0

Related Questions