E
eratchev
Setting the ValueMember property of a ComboBox to a name of a property
that is not browsable throws the following exception.
System.ArgumentException: Could not bind to the new display member.
Parameter name: newDisplayMember
It works fine if I set Browsable to true.
Has anyone encountered this before? Seems like a bug to me.
This is how I set up the DataSource:
ArrayList list = new ArrayList();
list.Add(new Person("John Doe"));
this.comboBox.DataSource = list;
this.comboBox.DisplayMember = "Name";
this.comboBox.ValueMember = "Name";
This is my Person class:
public class Person
{
string _name;
public Person(string name)
{
this._name = name;
}
[Browsable(false)]
public string Name
{
get { return this._name; }
set { this._name = value; }
}
}
Here is the complete code listing:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace BrowsableAttributeTest
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ComboBox comboBox;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
ArrayList list = new ArrayList();
list.Add(new Person("John Doe"));
this.comboBox.DataSource = list;
this.comboBox.DisplayMember = "Name";
try
{
this.comboBox.ValueMember = "Name";
}
catch(Exception e)
{
MessageBox.Show(e.ToString(), e.GetType().ToString());
}
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.comboBox = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// comboBox
//
this.comboBox.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox.Location = new System.Drawing.Point(24, 32);
this.comboBox.Name = "comboBox";
this.comboBox.Size = new System.Drawing.Size(184, 21);
this.comboBox.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.comboBox);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
public class Person
{
string _name;
public Person(string name)
{
this._name = name;
}
[Browsable(false)]
public string Name
{
get { return this._name; }
set { this._name = value; }
}
}
}
that is not browsable throws the following exception.
System.ArgumentException: Could not bind to the new display member.
Parameter name: newDisplayMember
It works fine if I set Browsable to true.
Has anyone encountered this before? Seems like a bug to me.
This is how I set up the DataSource:
ArrayList list = new ArrayList();
list.Add(new Person("John Doe"));
this.comboBox.DataSource = list;
this.comboBox.DisplayMember = "Name";
this.comboBox.ValueMember = "Name";
This is my Person class:
public class Person
{
string _name;
public Person(string name)
{
this._name = name;
}
[Browsable(false)]
public string Name
{
get { return this._name; }
set { this._name = value; }
}
}
Here is the complete code listing:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace BrowsableAttributeTest
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ComboBox comboBox;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
ArrayList list = new ArrayList();
list.Add(new Person("John Doe"));
this.comboBox.DataSource = list;
this.comboBox.DisplayMember = "Name";
try
{
this.comboBox.ValueMember = "Name";
}
catch(Exception e)
{
MessageBox.Show(e.ToString(), e.GetType().ToString());
}
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.comboBox = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// comboBox
//
this.comboBox.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox.Location = new System.Drawing.Point(24, 32);
this.comboBox.Name = "comboBox";
this.comboBox.Size = new System.Drawing.Size(184, 21);
this.comboBox.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.comboBox);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
public class Person
{
string _name;
public Person(string name)
{
this._name = name;
}
[Browsable(false)]
public string Name
{
get { return this._name; }
set { this._name = value; }
}
}
}