473,386 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 2207
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Victor Jones | last post by:
I have a general question about the approach towards databinding controls with objects. Apart from the databinding offered by .NET to bind data, it can be extended to have the same behavior with...
0
by: Victor Jones | last post by:
I have a general question about the approach towards databinding controls with objects. Apart from the databinding offered by .NET to bind data, it can be extended to have the same behavior with...
4
by: Jason S | last post by:
I haven't been able to find a clear answer to this and I'm hoping someone could enlighten me. As pertains to databinding a control in a repeating fashion(datagrid, repeater, etc.) what event...
4
by: dtblankenship | last post by:
Hello everyone, I know this question has been asked many times in the forums, and after spending a few days reading, I am still confused as to the answer. I have a ListBox (lstBox),...
2
by: Al Smith | last post by:
I kind of understand how the below works, however I am trying to do it at runtime vrs design time. <asp:TextBox id="TextBox1" runat="server" Text='<%# StateList.SelectedItem.Text...
2
by: Shane | last post by:
When I click on the DataBinding in the properties window a list of options open up called Advanced,Tag and Text. I would like to know what Tag and Text are set to? I hope to Bind a text box to a...
9
by: Dennis | last post by:
I have tried using Databinding for my application but always seem to find it very restrictive (maybe I don't completely understand it enough). I always seem to find it much easier to display a...
5
by: Mark R. Dawson | last post by:
Hi all, I may be missing something with how databinding works but I have bound a datasource to a control and everything is great, the control updates to reflect the state of my datasource when I...
1
by: Zak Lomakus | last post by:
Hi, From my main page (default.aspx) I am calling another .aspx (e.g. otherpage.aspx) page through Javascript using window.showModalDialog. otherpage.aspx has a databoud control (webchart),...
0
by: rb | last post by:
I'm struggling with (probably) basic things using SqlDataSource and DataList. Here's the problem: I need to read the resultset returned by SqlDataSource to perform actions related to visual...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.