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

C# Databinding Issue

I am having a behaviour problem with Databinding on a C# WinForm. I
have three textboxes and a Checkbox bound to a dataset. The desired
behaviour is when I check/uncheck the checkbox, I want to either
enable, or disable and clear the corresponding textboxes.

I want the fact that I cleared the text in the textboxes to reflect in
the dataset, so I am calling the EndCurrentEdit() method on the
currency manager to update the dataset within the event on the
checkbox. The problem is the checkbox will not check/uncheck properly
due to the fact the currency manager is firing. If I click on the
checkbox to uncheck it in runtime, the textboxes clear, but the
checkbox remains in a checked state.

Am I doing this properly by calling EndCurrentEdit() on the currency
manager? How do I reflect the clearing of the textboxes in the
dataset? I should clarify, that if I clear the textboxes in code, when
the focus of the form changes to a bound control, it replaces the text
back into the cleared textboxes.
//method called when the form is loading to create the bindings
private void BindControls()
{
textbox1.DataBindings.Add(new Binding("Text", _myDataSet,
"MyTable.Field1"));
textbox2.DataBindings.Add(new Binding("Text", _myDataSet,
"MyTable.Field2"));
textbox3.DataBindings.Add(new Binding("Text", _myDataSet,
"MyTable.Field3"));
checkbox1.DataBindings.Add(new Binding("Checked", _myDataSet,
"MyTable.Field4"));

//currency manager declared a member variable tothe form
_mCurrencyManager = null;
_mCurrencyManager = (CurrencyManager)this.BindingContext[_myDataSet,
"MyTable"];
}

//event on the check box which fires when checked/unchecked
private void chkCustomAssembly_CheckedChanged(object sender,
System.EventArgs e)
{
if(chkCustomAssembly.Checked == true)
{
textbox1.Enabled = true;
textbox2.Enabled = true;
textbox3.Enabled = true;
}
else
{
textbox1.Text = "";
textbox2.Text = "";
textbox3.Text = "";

textbox1.Enabled = false;
textbox2.Enabled = false;
textbox3.Enabled = false;
}

//update the binding currency manager to reflect the changes
//this call causes a problem with the behaviour of the checkbox
_mCurrencyManager.EndCurrentEdit();
}
Jul 21 '05 #1
0 1448

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

Similar topics

0
by: Richard | last post by:
Hi, I'm having issues with DataBinding. I have a Form with two data bound comboboxes on it. When you select something in one combobox I may {or may not} want to change the selected item in the...
3
by: Kevin Swanson | last post by:
I'm writing what should be a very simple app against an Oracle database. The app has a number of user controls, any one of which is loaded into a main display page using the loadControl method,...
13
by: Michael Maes | last post by:
Hi, I have a UserControl containing some controls of which one is a ComboBox. All the InternalControls are Private and some are allowed to be accessed through Public Methods. One of the things I...
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...
9
by: J055 | last post by:
Hi I have a very simple configuration of the GridView with paging and sorting. When I do a postback the DataBinding event fires twice - in both the ProcessPostData and PreRender stages of the...
1
by: CorporateCoder | last post by:
Hi, I am trying to bind the selected value of a databound dropdown box in a databound gridview control to the value being displayed in the template column the dropdown box has been added to. ...
1
by: Owen Blacker | last post by:
I've spent loads of time Googling to try to work this one out and I'm sure it's something obvious. I get an InvalidOperationException reading "Databinding methods such as Eval(), XPath(), and...
8
by: Dirk | last post by:
Hello, I have a problem to use databinding with my business layer classes. My data class does not have simple properties (string, int or datetime), instead, all my properties are objects of the...
1
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hello to all, I want to know if DataBinding in asp.net 2,0 is better than to fill up the values of the controls of the following form: this.miControlTextBox.Text = valorParaControlTextbox; ...
0
by: nelsonbrodyk | last post by:
Hey All, I have been able to set up a databinding to a property with the following code: <TextBox x:Name="txtTextBox" Text="{Binding Path=NameFirst, Mode=TwoWay,...
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: 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)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.