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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

how to fill grid control from datatable

Thread ID:

Created:

Updated:

Platform:

Replies:

129535 Mar 23,2017 10:49 PM UTC Mar 24,2017 07:29 AM UTC WinForms 1
loading
Tags: GridControl
jorge rigola
Asked On March 23, 2017 10:49 PM UTC

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.-

Arulpriya Ramalingam [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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

;