views:

372

answers:

0

I've enabled the AutoComplete functionality on a DataGridView using the following code:

    private void grid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        if (e.Control is DataGridViewTextBoxEditingControl)
        {
            var te = (DataGridViewTextBoxEditingControl)e.Control;
            te.AutoCompleteMode = AutoCompleteMode.Append;
            te.AutoCompleteSource = AutoCompleteSource.CustomSource;
            te.AutoCompleteCustomSource = this.GetCustomSource((DataGridView)sender);
        }
    }

    private Dictionary<String, AutoCompleteStringCollection> autoCompleteCollections = new Dictionary<String, AutoCompleteStringCollection>();
    private AutoCompleteStringCollection GetCustomSource(DataGridView gridView)
    {
        var column = gridView.Columns[grid.SelectedCells[0].ColumnIndex];

        if (!autoCompleteCollections.ContainsKey(column.Name))
        {
            var collection = new AutoCompleteStringCollection();

            switch (column.HeaderText)
            {
                case "Make":
                    collection.AddRange((
                        from row in gridView.Rows.OfType<DataGridViewRow>()
                        select (String)row.Cells[column.Index].Value).Distinct().OrderBy(m => m).ToArray());
                    break;
            }

            autoCompleteCollections.Add(column.Name, collection);
        }
        return autoCompleteCollections[column.Name];
    }

However, when I try to run the app, it crashes when I try to edit any cell in a column that has been assigned autocomplete information when I change the value.

This is happening inside Visual Studio 2008 SP1, running on Windows 7 Ultimate 64.

Each time, I get two events logged in my computer's application log:

Event ID 1000:

Faulting application name: BypassCompatEditor.vshost.exe, version: 9.0.30729.1, time stamp: 0x488f1c9b Faulting module name: shell32.dll, version: 6.1.7600.16385, time stamp: 0x4a5be054 Exception code: 0xc0000005 Fault offset: 0x0000000000094fe9 Faulting process id: 0xda4 Faulting application start time: 0x01ca34d51bddf3f3 Faulting application path: D:\Source\DanDoes.NET\BypassCompatEditor\BypassCompatEditor\bin\Debug\BypassCompatEditor.vshost.exe Faulting module path: C:\Windows\system32\shell32.dll Report Id: 6a6038e4-a0c8-11de-887b-0019b936fcbf

Event ID 1001:

Fault bucket , type 0 Event Name: APPCRASH Response: Not available Cab Id: 0

Problem signature: P1: BypassCompatEditor.vshost.exe P2: 9.0.30729.1 P3: 488f1c9b P4: shell32.dll P5: 6.1.7600.16385 P6: 4a5be054 P7: c0000005 P8: 0000000000094fe9 P9: P10:

Attached files: C:\Users\Daniel.HQ\AppData\Local\Temp\WER7AB2.tmp.WERInternalMetadata.xml

These files may be available here: C:\Users\Daniel.HQ\AppData\Local\Microsoft\Windows\WER\ReportArchive\AppCrash_BypassCompatEdit_36f85695fa6b32232b8ec2415f5d6fbd157fe8_00d97ed7

Analysis symbol: Rechecking for solution: 0 Report Id: 6a6038e4-a0c8-11de-887b-0019b936fcbf Report Status: 1

I turned on breaking all thrown exceptions, but it doesn't break at all, it just crashes immediately. Any suggestions?