Call stack:
Telerik.WinControls.GridView.dll!Telerik.WinControls.UI.GridGroupHeaderRowElement.Initialize(Telerik.WinControls.UI.GridViewRowInfo rowInfo) Line 100 at Telerik.WinControls.UI\GridGroupHeaderRowElement.cs(100) Telerik.WinControls.GridView.dll!Telerik.WinControls.Export.GridExportUtils.GetRowHeight(Telerik.WinControls.UI.RadGridView radGridView, Telerik.WinControls.UI.RowElementProvider rowProvider, Telerik.WinControls.UI.CellElementProvider cellProvider, Telerik.WinControls.UI.GridViewRowInfo gridViewRowInfo, bool exportVisualSettings) Line 158 at Telerik.WinControls.Export\GridExportUtils.cs(158) Telerik.WinControls.GridView.dll!Telerik.WinControls.Export.GridViewSpreadExport.AddRow(Telerik.WinControls.UI.GridViewRowInfo gridViewRowInfo, int rowIndex) Line 960
maskBoxColumn.FormatInfo = CultureInfo.CreateSpecificCulture("en-AE");
In this scenario, the RadGridView.DataSource property is set to Microsoft.EntityFrameworkCore.ChangeTracking.ObservableCollectionListSource. When the RadGridView.Rows.Remove() method is called an IndexOutOfRange exception is thrown.
In this case, the culture of the application is different from the culture of the machine. In this particular case, both cultures have different long date time format strings. current format mm/dd/yyyy compare to the one which the control is loading dd/mm/yyyy.
As a workaround, we can apply InvariantCulture before loading the XML and return the previous one after this:
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
grid.LoadLayout(xml);
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
Please refer to the attached sample video.
StackTrace:
Message: Object reference not set to an instance of an object. Telerik.WinControls.UI.RadGridViewDragDropService.GetDragImageHint(ContentAlignment textAlignment, Bitmap hintImage, RectangleF textRectangle, Int32 hintImageWidth) Telerik.WinControls.UI.ColumnChooserItem.GetDragHintCore() Telerik.WinControls.RadItem.Telerik.WinControls.ISupportDrag.GetDragHint() Telerik.WinControls.RadDragDropService.PrepareContext():80 Telerik.WinControls.RadDragDropService.HandleMouseMove(Point mousePos):40 Telerik.WinControls.UI.RadGridViewDragDropService.HandleMouseMove(Point mousePosition):13 Telerik.WinControls.RadDragDropService.Telerik.WinControls.IMessageListener.PreviewMessage(Message& msg):150 Telerik.WinControls.RadMessageFilter.NotifyGetMessageEvent(Message& msg):41 Telerik.WinControls.RadMessageFilter.GetMessageHookProc(Int32 code, IntPtr wParam, IntPtr lParam):36
Code snippet for reproducing the error:
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Title", typeof(string));
dt.Columns.Add("Price", typeof(decimal));
for (int i = 0; i < 10; i++)
{
dt.Rows.Add(i, "Row" + i, 0);
}
this.radGridView1.DataSource = dt;
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
GridViewSummaryItem summaryItem = new GridViewSummaryItem();
summaryItem.Name = "Price";
summaryItem.Aggregate = GridAggregateFunction.StDev;
GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
summaryRowItem.Add(summaryItem);
this.radGridView1.SummaryRowsBottom.Add(summaryRowItem);
With the current implementation, you can drop a column from the ColumnChooser window into the row. The column will be added to a place that reflects its position in the RadGridView Columns collection.
To reproduce:
public RadForm1()
{
InitializeComponent();
PopulateGrid();
}
private void radButton1_Click(object sender, EventArgs e)
{
GridViewSpreadExport spreadExporter = new GridViewSpreadExport(this.radGridView1);
SpreadExpo
rtRenderer exportRenderer = new SpreadExportRenderer();
spreadExporter.ExportHierarchy = true;
spreadExporter.ExportVisualSettings = true;
spreadExporter.ChildViewExportMode = Telerik.WinControls.UI.Export.ChildViewExportMode.ExportAllViews;
string fileName = @"..\..\exportedFile" + DateTime.Now.ToLongTimeString().Replace(":", "_") + ".xlsx";
spreadExporter.RunExport(fileName, exportRenderer);
Process.Start(fileName);
}
public void PopulateGrid()
{
List<GridResults.ChildCollectionFirst> firstCollection = new List<GridResults.ChildCollectionFirst>
{
new GridResults.ChildCollectionFirst
{
Test1 = "First Child"
}
}.ToList();
List<GridResults.ChildCollectionSecond> secondCollection = new List<GridResults.ChildCollectionSecond>
{
new GridResults.ChildCollectionSecond
{
Test2 = "Second Child"
}
}.ToList();
List<GridResults.ChildCollectionThird> thirdCollection = new List<GridResults.ChildCollectionThird>
{
new GridResults.ChildCollectionThird
{
Test3 = "Third Child"
}
}.ToList();
List<GridResults.ChildCollectionFourth> fourthCollection = new List<GridResults.ChildCollectionFourth>
{
new GridResults.ChildCollectionFourth
{
Test4 = "Fourth Child"
}
}.ToList();
var resultsList = new List<GridResults>
{
new GridResults
{
Id = "First Parent",
Value = "Test Value 1",
ChildCollection1 = new List<GridResults.ChildCollectionFirst>(),
ChildCollection2 = new List<GridResults.ChildCollectionSecond>(),
ChildCollection3 = new List<GridResults.ChildCollectionThird>(),
ChildCollection4 = new List<GridResults.ChildCollectionFourth>()
},
new GridResults
{
Id = "Second Parent",
Value = "Test Value 2",
ChildCollection1 = firstCollection,
ChildCollection2 = secondCollection,
ChildCollection3 = thirdCollection,
ChildCollection4 = fourthCollection
},
new GridResults
{
Id = "Third Parent",
Value = "Test Value 3",
ChildCollection1 = new List<GridResults.ChildCollectionFirst>(),
ChildCollection2 = new List<GridResults.ChildCollectionSecond>(),
ChildCollection3 = new List<GridResults.ChildCollectionThird>(),
ChildCollection4 = new List<GridResults.ChildCollectionFourth>()
},
new GridResults
{
Id = "Fourth Parent",
Value = "Test Value 4",
ChildCollection1 = new List<GridResults.ChildCollectionFirst>(),
ChildCollection2 = new List<GridResults.ChildCollectionSecond>(),
ChildCollection3 = new List<GridResults.ChildCollectionThird>(),
ChildCollection4 = new List<GridResults.ChildCollectionFourth>()
},
new GridResults
{
Id = "Fifth Parent",
Value = "Test Value 5",
ChildCollection1 = new List<GridResults.ChildCollectionFirst>(),
ChildCollection2 = new List<GridResults.ChildCollectionSecond>(),
ChildCollection3 = new List<GridResults.ChildCollectionThird>(),
ChildCollection4 = new List<GridResults.ChildCollectionFourth>()
},
new GridResults
{
Id = "Sixth Parent",
Value = "Test Value 6",
ChildCollection1 = new List<GridResults.ChildCollectionFirst>(),
ChildCollection2 = new List<GridResults.ChildCollectionSecond>(),
ChildCollection3 = new List<GridResults.ChildCollectionThird>(),
ChildCollection4 = new List<GridResults.ChildCollectionFourth>()
}
};
// radGridView1.BeginUpdate();
radGridView1.DataSource = resultsList;
// radGridView1.EndUpdate();
foreach (GridViewTemplate t in this.radGridView1.Templates)
{
t.AutoSizeColumnsMode= GridViewAutoSizeColumnsMode.Fill;
}
}
public class GridResults
{
[DisplayName("ID")]
public string Id { get; set; }
[DisplayName("Value")]
public string Value { get; set; }
[DisplayName("Child Collection 1")]
public List<ChildCollectionFirst> ChildCollection1 { get; set; }
[DisplayName("Child Collection 2")]
public List<ChildCollectionSecond> ChildCollection2 { get; set; }
[DisplayName("Child Collection 3")]
public List<ChildCollectionThird> ChildCollection3 { get; set; }
[DisplayName("Child Collection 4")]
public List<ChildCollectionFourth> ChildCollection4 { get; set; }
[DisplayName("Child Collection 1")]
public class ChildCollectionFirst
{
[DisplayName("Test Header")]
public string Test1 { get; set; }
}
[DisplayName("Child Collection 2")]
public class ChildCollectionSecond
{
[DisplayName("Test Header 2")]
public string Test2 { get; set; }
}
[DisplayName("Child Collection 3")]
public class ChildCollectionThird
{
[DisplayName("Test Header 3")]
public string Test3 { get; set; }
}
[DisplayName("Child Collection 4")]
public class ChildCollectionFourth
{
[DisplayName("Test Header 4")]
public string Test4 { get; set; }
}
}
The observed result with duplicated rows is demonstrated here: