473,320 Members | 1,949 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,320 software developers and data experts.

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(object sender,
System.ComponentModel.CancelEventArgs e)
{
Control control = (Control)
sender; control.BindingContext[test].EndCurrentEdit();
results.Text = test.BindingTestString;
}

but not with:

private void OnFocusChange(object sender,
System.ComponentModel.CancelEventArgs e)
{
Control control = (Control) sender;
control.BindingContext[test, "BindingTestString"].EndCurrentEdit();
results.Text = test.BindingTestString;
}

or the below code.

Thanks

Wesley


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
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.ComponentModel.Container components = null;

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

Binding binding = new Binding("Text", test, "BindingTestString");
binder.DataBindings.Add(binding);
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
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 InitializeComponent()
{
this.binder = new System.Windows.Forms.TextBox();
this.results = new System.Windows.Forms.TextBox();
this.done = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// binder
//
this.binder.Location = new System.Drawing.Point(24, 16);
this.binder.Name = "binder";
this.binder.Size = new System.Drawing.Size(352, 20);
this.binder.TabIndex = 0;
this.binder.Text = "";
this.binder.Validating += new
System.ComponentModel.CancelEventHandler(this.OnFo cusChange);

//
// results
//
this.results.Location = new System.Drawing.Point(24, 48);
this.results.Name = "results";
this.results.Size = new System.Drawing.Size(352, 20);
this.results.TabIndex = 1;
this.results.Text = "";
//
// done
//
this.done.Location = new System.Drawing.Point(304, 80);
this.done.Name = "done";
this.done.TabIndex = 2;
this.done.Text = "DONE";
this.done.Click += new System.EventHandler(this.done_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(400, 116);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.done,
this.results,
this.binder});
this.Name = "Form1";
this.Text = "Binding Test";
this.ResumeLayout(false);

}
#endregion

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

private void OnFocusChange(object sender,
System.ComponentModel.CancelEventArgs e)
{
Control control = (Control) sender;
control.BindingContext[control.DataBindings].EndCurrentEdit();
results.Text = test.BindingTestString;
}
private void done_Click(object sender, System.EventArgs e)
{

this.Dispose(true);
}
}

class BindingTest
{
string internalString = "default";

public BindingTest(){}

public string BindingTestString
{
get{return internalString;}
set{internalString = value;}
}
}
}
Nov 15 '05 #1
0 2736

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

Similar topics

0
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...
16
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...
1
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...
0
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...
19
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...
19
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...
0
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...
14
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...
9
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...
3
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.