0

We're sending query results to a grid. Different columns, with different datatypes, on each query. Is there a grid control that will

a) autopopulate the columns based on the dataset that is set to be its datasource

AND

b) correctly render the linefeeds or carriage returns that appear in a text string?

Let's say there was an address column with this data:

123 Main St@Apt #2@New York NY 10016

where instead of @ there was actually a char(10). We would like it to render in the cell as

123 Main St
Apt #2
New York NY 10016

There's no design-time preparation in which columns are defined and editors assigned. This is all ad hoc.

1
1

Essential Grid supports auto populating data from the underlying data source and the DataSource property can be used to set the data source to the Grid.

Sample link

#region DataSource 
DataTable dataTable = new DataTable(); 
dataTable.Columns.Add("ID"); 
dataTable.Columns.Add("Name"); 
dataTable.Columns.Add("Category"); 
dataTable.Columns.Add("SampleData"); 
dataTable.Columns.Add("Description"); 
for (int i = 0; i < 10; i++) 
{ 
DataRow dataRow = dataTable.NewRow(); 
dataRow[0] = i; 
dataRow[1] = "Name" + i.ToString(); 
dataRow[2] = "Category"+i; 
dataRow[3] = "Data" + i.ToString(); 
dataRow[4] = "Decription" + i.ToString(); 
dataTable.Rows.Add(dataRow); 
} 
//to set the data source for the grid. 
this.gridGroupingControl1.DataSource = dataTable; 
#endregion 

By default, the char(10) (i.e. the new line char) is addressed as “\r\b”. In order to render the char(10) value in the GridGroupingControl, the CellValue can be modified for display using the QueryCellStyleInfo event.

#region Event
//Event triggering 
this.gridGroupingControl1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo);
//Event customization 
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) 
{ 
if (e.Style.CellValue != null) 
{ 
    string cellValue = e.Style.CellValue.ToString(); 
    if (cellValue.Contains("char(10")) 
    { 
        cellValue.Replace("char(10)", "\r\b"); 
        e.Style.CellValue = cellValue; 
    } 
} 
} 

#endregion 

Syncfusion Windows Forms Grid

The entire product is available for free with no limitations through the community license if you qualify.

Note: I work for Syncfusion

1
  • Thanks for the info. I will take a look. Jan 9 '18 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.