D
dvestal
The example below creates a ComboBox, and binds its Text field to the
Text field of a textbox. When the user types into the textbox, the
corresponding ComboBox value is selected.
What is the best way to know at runtime whether the user has typed a
value that isn't in the ComboBox's list of valid values? I need a
solution that works using the built-in binding events, rather than
using manual checking of the value when it changes.
I'd like to set an ErrorProvider to alert the user to the invalid
value.
using System;
using System.Windows.Forms;
namespace A
{
public class C
{
[STAThread]
static void Main()
{
Form form = new Form();
TextBox txt = new TextBox();
txt.Top = 10;
txt.Left = 10;
txt.Text = "1";
ComboBox cbo = new ComboBox();
cbo.Top = txt.Bottom + 10;
cbo.Left = 10;
cbo.DropDownStyle = ComboBoxStyle.DropDownList;
cbo.Items.AddRange(new object[]{ 1, 2 });
cbo.DataBindings.Add("Text", txt, "Text");
form.Controls.Add(txt);
form.Controls.Add(cbo);
form.ShowDialog();
}
}
}
Text field of a textbox. When the user types into the textbox, the
corresponding ComboBox value is selected.
What is the best way to know at runtime whether the user has typed a
value that isn't in the ComboBox's list of valid values? I need a
solution that works using the built-in binding events, rather than
using manual checking of the value when it changes.
I'd like to set an ErrorProvider to alert the user to the invalid
value.
using System;
using System.Windows.Forms;
namespace A
{
public class C
{
[STAThread]
static void Main()
{
Form form = new Form();
TextBox txt = new TextBox();
txt.Top = 10;
txt.Left = 10;
txt.Text = "1";
ComboBox cbo = new ComboBox();
cbo.Top = txt.Bottom + 10;
cbo.Left = 10;
cbo.DropDownStyle = ComboBoxStyle.DropDownList;
cbo.Items.AddRange(new object[]{ 1, 2 });
cbo.DataBindings.Add("Text", txt, "Text");
form.Controls.Add(txt);
form.Controls.Add(cbo);
form.ShowDialog();
}
}
}