[Mono-bugs] [Bug 424270] New: Combobox: ArgumentNullException on set_SelectedItem

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Sep 8 06:06:03 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=424270


           Summary: Combobox: ArgumentNullException on set_SelectedItem
           Product: Mono: Class Libraries
           Version: SVN
          Platform: x86
        OS/Version: Windows Vista
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Windows.Forms
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: kobruleht2 at hot.ee
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


To reproduce:

1. Run code
2. Press Tab

Observed:


Unhandled Exception: System.ArgumentNullException: Argument cannot be null.

Parameter name: value

  at System.Windows.Forms.ComboBox+ObjectCollection.IndexOf (System.Object
value) [0x00000] 
  at System.Windows.Forms.ComboBox.set_SelectedItem (System.Object value)
[0x00000] 
  at ReportDialogForm+MyComboBox.DoValidating () [0x00000] 
  at ReportDialogForm+MyComboBox.OnValidating
(System.ComponentModel.CancelEventArgs e) [0x00000] 
  at System.Windows.Forms.Control.FireValidating
(System.ComponentModel.CancelEventArgs ce) [0x00000] 
  at System.Windows.Forms.ContainerControl.ValidateControl
(System.Windows.Forms.Control c) [0x00000] 
  at System.Windows.Forms.ContainerControl.set_ActiveControl
(System.Windows.Forms.Control value) [0x00000] 
  at System.Windows.Forms.Control.Select (Boolean directed, Boolean forward)
[0x00000] 
..

Code:


using System;
using System.ComponentModel;
using System.Windows.Forms;

class Test
{
    static void Main()
    {
        Application.Run(new ReportDialogForm());
    }
}

class ReportDialogForm : Form
{

    public ReportDialogForm()
    {
        Controls.Add(new MyComboBox());
        var tb = new TextBox();
        tb.Top = 30;
        Controls.Add(tb);
    }

    class MyComboBox : ComboBox
    {
        internal MyComboBox()
        {
            DisplayMember = "DisplayMember";
            ValueMember = "ValueMember";
            var picklist = new BindingList<PickListEntity>();
            picklist.Insert(0, new PickListEntity() { DisplayMember = "" });
            DataSource = picklist;
            DropDownStyle = ComboBoxStyle.DropDownList;
        }

        protected override void OnValidating(CancelEventArgs e)
        {
            if (!DoValidating())
            {
                e.Cancel = true;
            }
            base.OnValidating(e);
        }

        internal bool DoValidating()
        {
            if (Text.Trim().Length == 0)
            {
                SelectedItem = null;
                return true;
            }

            int pos = FindStringExact(Text.Trim());
            if (pos >= 0)
            {
                SelectedIndex = pos;
                return true;
            }

            pos = FindString(Text.Trim());
            if (pos >= 0)
            {
                SelectedIndex = pos;
                return true;
            }
            BindingList<PickListEntity> foundEntities = new
BindingList<PickListEntity>();
            return true;
        }

        protected override void OnValidated(EventArgs e)
        {
                if (DataBindings["SelectedValue"] != null)
                    DataBindings["SelectedValue"].WriteValue();
            base.OnValidated(e);
        }
    }
}

class PickListEntity
{
    public string DisplayMember { get; set; }
    public object ValueMember { get; set; }

    public override string ToString()
    {
        return ValueMember + "," + DisplayMember;
    }
}


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list