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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set a value into the cell in WinForms GridControl?

Platform: WinForms |
Control: GridControl

Setting cellvalue

The style object holds all the information that affects the cell’s appearance. You can set the value for the cell by using the CellValue property.

Use a two-parameter indexer rowIndex, columnIndex on your Gridcontrol object to get a reference to that particular cell’s style.


int rowIndex = 1, columnIndex = 2;
gridControl1[rowIndex, columnIndex].CellValue = "PI";
gridControl1[rowIndex, columnIndex].CellValue = 3.14159;
gridControl1[rowIndex, columnIndex].CellValue = DateTime.Now;


Dim rowIndex As Integer = 1, columnIndex As Integer = 2
gridControl1(rowIndex, columnIndex).CellValue = "PI"
rowIndex += 1
gridControl1(rowIndex, columnIndex).CellValue = 3.14159
rowIndex += 1
gridControl1(rowIndex, columnIndex).CellValue = DateTime.Now

You can also set CellValue by using QueryCellInfo event.


//Hook the QueryCellInfo event in Form_Load 
gridControl1.QueryCellInfo += gridControl1_QueryCellInfo;
void gridControl1_QueryCellInfo(object sender,GridQueryCellInfoEventArgs e)
    if (e.ColIndex == 3)
        if (e.RowIndex == 1)
            e.Style.CellValue = "Fraction";
        if(e.RowIndex == 2)
            e.Style.CellValue = "22/7";
        if(e.RowIndex == 3)
            e.Style.CellValue = DateTime.Now;


'Hook the QueryCellInfo event in Form_Load 
Private gridControl1.QueryCellInfo += AddressOf gridControl1_QueryCellInfo
Private Sub gridControl1_QueryCellInfo(ByVal sender As Object, ByVal e As GridQueryCellInfoEventArgs)
    If e.ColIndex = 3 Then
          If e.RowIndex = 1 Then
                e.Style.CellValue = "Fraction"
          End If
          If e.RowIndex = 2 Then
                e.Style.CellValue = "22/7"
          End If
          If e.RowIndex = 3 Then
                e.Style.CellValue = DateTime.Now
          End If
    End If
End Sub



You can set different data types for the CellValue since its data type is an object.


Set the cellvalue in gridcontrol

Figure 1: Setting CellValue in Gridcontrol


C#: SetCellValue

VB: SetCellValue

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon 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.Close Icon

Live Chat Icon For mobile