468,321 Members | 1,817 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,321 developers. It's quick & easy.

DataBinding Question

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();
}
}
}

Aug 8 '07 #1
2 2043
Best way depends on how you detect that user has finished typing.

Otherwise you might handle text changed event for text box and filter combo
list for matches. If at any time match list is empty, you can display your
message box.

What do you mean by "using binding events"?

<dv*****@gmail.comwrote in message
news:11*********************@w3g2000hsg.googlegrou ps.com...
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();
}
}
}

Aug 8 '07 #2
On Aug 8, 6:17 pm, "AlexS" <salexru200...@SPAMrogers.comPLEASEwrote:
Best way depends on how you detect that user has finished typing.

Otherwise you might handle text changed event for text box and filter combo
list for matches. If at any time match list is empty, you can display your
message box.

What do you mean by "using binding events"?
I mean that I'd much rather use the Binding.Format, Binding.Parse, or
Binding.BindingComplete events to check this, or some other binding-
specific event of which I'm unaware.

Aug 9 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Victor Jones | last post: by
reply views Thread by Victor Jones | last post: by
4 posts views Thread by Jason S | last post: by
2 posts views Thread by Al Smith | last post: by
2 posts views Thread by Shane | last post: by
9 posts views Thread by Dennis | last post: by
5 posts views Thread by Mark R. Dawson | last post: by
1 post views Thread by Zak Lomakus | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by howard w | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.