1 Answer, 1 is accepted
According to the provided information, it is not clear what is the column type for this particular column. Is it a GridViewTextBoxColumn? If yes, usually this expects text value and the grouping is performed over the string values.
However, for any unsupported format, it is suitable to use the custom grouping functionality which is a flexible mechanism for creating groups by using custom logic. More information is available here: https://docs.telerik.com/devtools/winforms/controls/gridview/grouping/custom-grouping
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
It is a GridViewTextBoxColumn containing the JSON formatted data. I'm not sure where the exception is produced, but the message results "Input string was not in a correct format". Because my RadGridView takes in generic data, I do not know which column will have JSON formatted data prior.
I can provide a copy of the StackTrace
I had done some extra work last week in other areas in the app and without knowing, I had fixed the issue.
However, thank you for taking the time to assist.
Correction: I had inadvertently found a workaround to the issue by disabling radGridView1.EnableCustomGrouping.
To better explain what I am attempting to do, I am taking whatever is in the data cell into the GroupHeader when grouping is triggered. I believe the error stems from the fact that e.FormatString is not escaping characters of the JSON formatted data, that is the quotes in this example are breaking e.FormatString. I'm setting the GroupHeader with this line:
e.FormatString = String.Format("{0} - Item Count: {1}", e.Value, _rowCount);
{"Field1":"Data1","Filed2":"Data2"}
Sorry for the quick response, but I found that String.Format has a problem { } characters. Is there a for C# to escape all characters ?
I've attached a copy of a small project to demonstrate the issue
The provided sample project is greatly appreciated. It seems that the problem occurs in the String.Format function and the passed JSON content to it. Formatting a string is more like a general programming question. That is why after some research in general programming forums I have found the following thread which seems to be useful on this topic:
https://stackoverflow.com/questions/91362/how-to-escape-braces-curly-brackets-in-a-format-string-in-net
I tested a similar approach on my end and it seems to work as expected now:
string value = "{RunFunc\":\"RunJob\"}";
int _rowCount = 10;
string test = String.Format("{0} - Item Count: {1}", value, _rowCount);
Note that the curly brackets from the JSON are confusing since they participate in the place holders for the Format.String. The possible solution that I can suggest is to use the custom grouping approach. I have prepared a sample code snippet for your reference:
this.radGridView1.EnableCustomGrouping = true;
this.radGridView1.CustomGrouping += RadGridView1_CustomGrouping;
private void RadGridView1_CustomGrouping(object sender, GridViewCustomGroupingEventArgs e)
{
string data = e.Row.Cells["Data"].Value.ToString();
e.GroupKey =string.Format("{{{0}}}", data);
e.Handled = true;
}
private void RadGridView1_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
{
try
{
int _rowCount = 0;
foreach (GridViewRowInfo row in e.Group)
{
_rowCount++;
}
e.FormatString = e.Group.Key.ToString() + " - Item Count: " + _rowCount;
}
catch (Exception ex)
{
MessageBox.Show($"Uncaught error in {System.Reflection.MethodBase.GetCurrentMethod().Name}: \n{ex.Message}", caption: "Error");
}
}
Please give it a try and see how it works on your end.
string data = e.Row.Cells[ColumnName].Value.ToString();