Reputation: 181
I have one winforms app and when I minimize the window I need that the processes still running. It's all ok until i set the RadGrid datasource : radGrid1.DataSource = datasource1;
When I set the datasource this way the app just freezes and nothing happens more.
After some search I've modified the code to:
radGrid1.BeginUpdate();
radGrid1.DataSource = datasource1;
and this way I can set the data source but my grid loses the format.
If I add the radGrid1.EndUpdate()
it freezes too.
What can I do do load the datasource and don't lose the format of my radgrid?
Best regards
Upvotes: 0
Views: 1114
Reputation: 465
I just came across this problem today in an app using Telerik RadGridView 2017.2.613.40. I had columns defined in code:
_grid.Columns.AddRange(
//...more columns
new GridViewCheckBoxColumn
{
Name = "IsSmallLabel",
FieldName = "IsSmallLabel",
MinWidth = 100,
MaxWidth = 100,
IsVisible = true,
ReadOnly = false,
HeaderText = "Small label"
},
new GridViewCheckBoxColumn
{
Name = "IsTechCard",
FieldName = "IsTechCard",
MinWidth = 100,
MaxWidth = 100,
IsVisible = true,
ReadOnly = false,
HeaderText = "Tech card"
});
And an OnCellFormatting event:
private void OnCellFormatting(object sender, CellFormattingEventArgs e)
{
try
{
var checkCell = e.CellElement as GridCheckBoxCellElement;
if (checkCell == null) return;
var poItem = e.Row.DataBoundItem as PurchaseOrderItem;
if (poItem == null) return;
if (string.Equals(e.Column.Name, "IsSmallLabel", StringComparison.OrdinalIgnoreCase))
{
checkCell.Visibility = !string.IsNullOrEmpty(poItem.LotNo) ? ElementVisibility.Visible : ElementVisibility.Collapsed;
checkCell.Value = !string.IsNullOrEmpty(poItem.LotNo);
}
else if (string.Equals(e.Column.Name, "IsTechCard", StringComparison.OrdinalIgnoreCase))
{
checkCell.Visibility = poItem.TechnologyCard != null ? ElementVisibility.Visible : ElementVisibility.Collapsed;
checkCell.Value = poItem.TechnologyCard != null;
}
}
catch (Exception ex)
{
_logger.Error(ex);
}
}
The two fields were actually missing from the model and adding them solved the problem with the app hanging. The issue seemed to be related to the formatting function as removing it would also stop the app from hanging.
Upvotes: 1
Reputation: 1519
To prevent the grid from traversing all data fields in that collection, set the GridViewTemplate.AutoGenerateColumns property to False. In this case, the additional fields that you might use when sorting, grouping, etc., should be included in the MasterGridViewTemplate.Columns collection. With these settings, only the properties that are used as column FieldName properties or those specified in the MasterGridViewTemplate.Columns will be extracted.
Should fix the problem you described with "losing the format".
Second problem, the program freezing, is not something I've encountered in the numerous of occasions I've worked with RadGridViews
in windows forms environments.
The only thing I can think of is that your datasource collection is too large, or items in the collection have too many fields that the RadGridView
is trying to generate columns for when the AutoGenerateColumns
property is set to true
.
Upvotes: 2