Skip to content

Commit 2fc2c35

Browse files
authored
Merge pull request #3 from klanderfri/fix-crash-when-comparing
Fix crash when comparing
2 parents b933ee8 + bdba34d commit 2fc2c35

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

FolderStructureAnalyser/Components/AnalyserPanels/FolderStructureComparerCtrl.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,28 @@ private void FolderStructureComparerCtrl_FolderStructureAnalysisFinished(object
117117
/// <param name="differences">The list of differences to show the user.</param>
118118
private void updateDataSource(BindingList<StructureDifference> differences)
119119
{
120-
gridControl.DataSource = differences;
120+
/* For some reason, assigning the differences directly to the
121+
* data-source, like so:
122+
*
123+
* gridControl.DataSource = differences;
124+
*
125+
* ... raises the exception below:
126+
*
127+
* System.Reflection.TargetInvocationException: 'Property accessor 'FullName' on object 'System.IO.FileInfo' threw the following exception:'Object does not match target type.''
128+
* TargetException: Object does not match target type.
129+
*
130+
* I do not know why, but assigning a new, empty binding list, and
131+
* then adding all the differences, one by one, seems to work.
132+
*
133+
* I speculate that the grid-control wants to be able to raise some
134+
* event for every row added to it, and that it can't do that when
135+
* all rows are added as a collection?
136+
*/
137+
gridControl.DataSource = new BindingList<StructureDifference>();
138+
foreach (var diff in differences)
139+
{
140+
(gridControl.DataSource as BindingList<StructureDifference>).Add(diff);
141+
}
121142
}
122143

123144
/// <summary>

FolderStructureAnalyser/Program.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Globalization;
23
using System.Windows.Forms;
34
using DevExpress.XtraEditors;
45
using FolderStructureAnalyser.Components;
@@ -15,6 +16,13 @@ static class Program
1516
[STAThread]
1617
static void Main()
1718
{
19+
//By setting the default thread culture to English, the exceptions
20+
//raised will be in English and not in Swedish (or whatever
21+
//language the local computer has), making error researching
22+
//(aka googling) easier.
23+
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
24+
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");
25+
1826
WindowsFormsSettings.ScrollUIMode = ScrollUIMode.Fluent;
1927
Application.EnableVisualStyles();
2028
Application.SetCompatibleTextRenderingDefault(false);

0 commit comments

Comments
 (0)