473,779 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Data Binding

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 2808

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

Similar topics

0
2349
by: Ann Morris | last post by:
INTRODUCTION One of the most powerful aspects of .NET and Windows Forms is data binding. Data binding is the process of associating user interface (UI) elements with a data source to generate a visual representation of data. Two types of data binding are available for Windows Forms: Simple Data Binding and Complex Data Binding. Simple data binding allows you to bind one data element to a control. In many situations you want to display...
16
3039
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For example dsParts.xsd and including that in the data tier. I then will create a class that looks like this Public Class CPart Inherits dsParts
1
2602
by: matty.hall | last post by:
There's a lot of information out there about data-binding UI objects (i.e. derived from Control) to non-UI custom business objects. Is it possible to do the same without any UI being involved at all? Here's an example: I want to do data binding on some of the properties of a TreeNode (namely its Name). Unfortunately, TreeNode does not derive from Control, so it doesn't have the "stock" data binding stuff. I'd like to create a new...
0
5676
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet) at TryThis.Form1.save() in C:\Documents and Settings\Nick\My Documents\...
19
2347
by: Simon Verona | last post by:
I'm not sure if I'm going down the correct route... I have a class which exposes a number of properties of an object (in this case the object represents a customer). Can I then use this object to databind to text boxes etc? I can't use a dataset as the object has loads of derived logic, for example updating one property may actually update several database fields for example.
19
2232
by: Larry Lard | last post by:
In the old days (VB3 era), there was a thing called the Data Control, and you could use it to databind controls on forms to datasources, and so (as the marketing speak goes), 'create database applications without writing a single line of code!!!'. Personally, and I know I wasn't alone in this, I was always suspicious of this claim, because one invariably ended up writing huge amounts of code attempting to get the automagical thing to do...
0
2216
by: mjsterz | last post by:
I've been working with VB .NET for less than a year and this is the first time I've posted on one of these groups, so let me apologize beforehand if I'm being unclear, not posting my issue correctly, posting to the wrong forum, or committing some other sort of faux pas. My team is developing a Windows Forms application using VS 2005 with SQL Server 2005 on the back end and we're having a problem using ComboBoxes data bound to lookup...
14
14659
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control so I get the ObjectDataSource. No problem ..... ObjectDataSource src = .... //is ok i have it
9
4026
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New DataTable("SliceInfo") Dim tblSliceRatings As New DataTable("SliceRatings") '.... All the adding datacolumns, datarows, etc. goes here.. DatasetInit.Tables.Add(tblSliceInfo)
3
2446
by: Max | last post by:
Hello, I made a windows form with a combo box and 4 text boxes. All 5 objects should get their data from a data set which is populated in the form load method. The combo box has item ids. When the users selects an item from the combo box I'd like the 4 text boxes to get populated with the corresponding item information from the same dataset table row that the combo box is pulling it's info from. Is there an easy way of doing this besides...
0
9636
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
9474
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
10138
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...
1
10074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9930
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
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
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.