473,587 Members | 2,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about data bindings

Why does the following code not work (displays the correct values in
the second textbox). if i chane the OnFocusChange method to the
following it will work:

private void OnFocusChange(o bject sender,
System.Componen tModel.CancelEv entArgs e)
{
Control control = (Control)
sender; control.Binding Context[test].EndCurrentEdit ();
results.Text = test.BindingTes tString;
}

but not with:

private void OnFocusChange(o bject sender,
System.Componen tModel.CancelEv entArgs e)
{
Control control = (Control) sender;
control.Binding Context[test, "BindingTestStr ing"].EndCurrentEdit ();
results.Text = test.BindingTes tString;
}

or the below code.

Thanks

Wesley


using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;

namespace BindingTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows. Forms.Form
{

BindingTest test = new BindingTest();

private System.Windows. Forms.TextBox binder;
private System.Windows. Forms.TextBox results;
private System.Windows. Forms.Button done;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

Binding binding = new Binding("Text", test, "BindingTestStr ing");
binder.DataBind ings.Add(bindin g);
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
} 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 InitializeCompo nent()
{
this.binder = new System.Windows. Forms.TextBox() ;
this.results = new System.Windows. Forms.TextBox() ;
this.done = new System.Windows. Forms.Button();
this.SuspendLay out();
//
// binder
//
this.binder.Loc ation = new System.Drawing. Point(24, 16);
this.binder.Nam e = "binder";
this.binder.Siz e = new System.Drawing. Size(352, 20);
this.binder.Tab Index = 0;
this.binder.Tex t = "";
this.binder.Val idating += new
System.Componen tModel.CancelEv entHandler(this .OnFocusChange) ;

//
// results
//
this.results.Lo cation = new System.Drawing. Point(24, 48);
this.results.Na me = "results";
this.results.Si ze = new System.Drawing. Size(352, 20);
this.results.Ta bIndex = 1;
this.results.Te xt = "";
//
// done
//
this.done.Locat ion = new System.Drawing. Point(304, 80);
this.done.Name = "done";
this.done.TabIn dex = 2;
this.done.Text = "DONE";
this.done.Click += new System.EventHan dler(this.done_ Click);
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(400, 116);
this.Controls.A ddRange(new System.Windows. Forms.Control[] {
this.done,
this.results,
this.binder});
this.Name = "Form1";
this.Text = "Binding Test";
this.ResumeLayo ut(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new Form1());
}

private void OnFocusChange(o bject sender,
System.Componen tModel.CancelEv entArgs e)
{
Control control = (Control) sender;
control.Binding Context[control.DataBin dings].EndCurrentEdit ();
results.Text = test.BindingTes tString;
}
private void done_Click(obje ct sender, System.EventArg s e)
{

this.Dispose(tr ue);
}
}

class BindingTest
{
string internalString = "default";

public BindingTest(){}

public string BindingTestStri ng
{
get{return internalString; }
set{internalStr ing = value;}
}
}
}
Nov 15 '05 #1
0 1450

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2156
by: StepH | last post by:
Hi, I'm building a little application, which the goal is to: 1./ Collect data via Serial line and or via a file (for playback). 2./ Display these data as graph, oscilloscope, ... How manage this ? 1./ Is each "display" must responsible to acquire/read the data ?
0
1779
by: Neo | last post by:
I was wondering what is the "right" way to deal with datasets is. Particularly sharing DataSets between forms. Here is my situation. I have a simple Customer Database, that holds some information about Customers including thier address. Lets call this Table "Customers". The Customers Table references another Table for Address information, for instance I have a table of "Zipcodes", Now I want an app with two forms, one form to browse my...
5
1314
by: gb | last post by:
hi, i'm working on a large project involving numerous tables. there are instances, that i only need to do a simple select statement for each table (e.g. select * from table1 or select fld1, fld3 from table1 or select fld1,fld2 from table2). my question is, do i need to create stored procedure (SP) for each? because if i do, i will be having a lot of SPs for a single table alone.
8
1581
by: jimscott77 | last post by:
Can someone help with the following problem? Original Question: TextBox1 is bound to a dataset and at runtime shows a value of "5" I am trying to use that value as follows: TextBoxA.Text = TextBox1.Text The result that I'd expect is that TextBoxA.Text would equal 5. The result that I get is that TextBoxA.Text equals "", or wit a Val(function) it equals 0.
3
1629
by: tomrobin | last post by:
Hi, I'm having trouble with data types. I understand that the double data type is 64-bit, which should correspond to 15 digits(?). However, it seems from running this program that it can only handle up to 6 digits: #include <iostream> using namespace std;
1
2095
by: David Veeneman | last post by:
How do I get the data bindings for a control that is bound at design time? I'm binding a DataGridView control to a data source at design time, using a BindingSource control. I set the grid's DataSource property to the BindingSource control, which the Data Source Configuration Wizard created for me. The data binding works fine when I run the app, but I can't get a reference to the DataGridView's data bindings.
4
1789
by: Paul | last post by:
Hi, I have a project configured as follows: Main form with a tabcontrol with 1 tab page and a panel with some text boxes in. This form also has some bindingsources dropped onto the form. When a selection is made the program instantiates a new class which creates several tabs on the main form each with a datagridview on. As you click on each tab a datatable is populated and bound to the datagridview. This all works ok.
3
1592
by: catstevens | last post by:
I'm trying to build a DTS package that will copy data from one server to another, and I'm using the latest teradata ODBC driver to connect to teradata. The problem is when i setup the dts package - DTS just sits there and hangs when i try to make a new data pump task. Any clues why this would occur? Also, in case you were curious, I am on sql server 2000 with service pack 4
1
1321
by: AliRezaGoogle | last post by:
Hi As I know ORM tools encapsulate table rows in objects. In other words we do not see rows or columns, instead we see objects with properties. But there are some GUI components that work with dataTables and dataRows. As an example a datagrid. A datagrid needs a dataSet or dataTable to show it's content. However my question is about these components. Working with ORM tools (like NHibernate) how can I feed objects (which are managed by ORM...
0
7924
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7854
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8219
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.