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

how to fill grid control from datatable

Hi ,

i am new in this tool. i need fill a grid control from a datatable.
other question, is posible change header names and hide number of rows?

br.-

1 Reply

AR Arulpriya Ramalingam Syncfusion Team March 24, 2017 07:29 AM UTC

Hi Jorge, 

Thanks for your interest in Syncfusion products. 

I need fill a grid control from a datatable 
In order  to copy the values form a data table to GridControl, PopulateValues() method can be used. Please refer the below code, 

//Populating values using PopulateValues method 
for (int row = 1; row <= this.gridControl1.RowCount; ++row) 
{ 
    for (int col = 1; col <= this.gridControl1.ColCount; ++col) 
    { 
        this.gridControl1.PopulateValues(GridRangeInfo.Cells(1, 1, this.gridControl1.RowCount, this.gridControl1.ColCount),dataTable); 
    } 
} 

Already we have provided this in our User Guide. Please refer the below link. 
 
Note 
The VirtualGrid is specifically designed to view the data which are in virtual mode (i.e. To view the data in data table, ArrayList, etc.,). Already we have provided the UG for Virtual Grid. Please make use of below link, 

 
Is possible change header names and hide number of rows? 
Suggestion 1 
The header text can be changed using Text property. Please refer the below code, 
gridControl1[0, 1].Text = "EmployeeID"; 
 
Suggestion 2 
The header text value can also be changed using CellValue property. Please make use of below code, 
gridControl1[0, 4].CellValue = "Designation"; 
 

Suggestion 3 
You can also set the header text using QueryCellInfo Event. Please refer the below code, 
//Event Triggering 
gridControl1.QueryCellInfo += GridControl1_QueryCellInfo; 
//Event Customization 
private void GridControl1_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) 
{ 
    if(e.RowIndex==0) 
    { 
        if(e.ColIndex==1) 
        { 
            e.Style.CellValue = "EmployeeID"; 
            e.Handled = true; 
        } 
        if (e.ColIndex == 2) 
        { 
            e.Style.Text = "EmployeeName"; 
            e.Handled = true; 
        } 
} 
 

Screenshot 
 
 
 


Regards, 
Arulpriya

Loader.
Up arrow icon