Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / October 2006

Tip: Looking for answers? Try searching our database.

BindingSource.AddNew() locks TextBox.Text property??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tomse - 23 Oct 2006 18:33 GMT
Hello,
I have simple databinding of textbox to bindingsource(bound to
dataset), created in form constructor:

public Form3(string xyz)
       {
           InitializeComponent();

           Program.bindingSource.AddNew();
           textBox1.DataBindings.Add("Text", Program.bindingSource,
"cmType");

           textBox1.Text = xyz;  // <-nothing happens
       }

all I want is to add a new row to dataset, and set a value of column
"cmType" programmatically in form constructor. Problem is that result
of
program above is blank textBox1, and no data in "cmType", although a
new row is being added to dataset.
I can fill textBox1 by typing the value manually on a runtime, or
programmatically in any event (onFormShow for eg.)
Am I missing something??
Anyone can help?
thx
Alterling - 24 Oct 2006 10:46 GMT
I can suggest do not set binded properties directly, consider using
CurrencyManager or PropertyManager.
Alterling - 24 Oct 2006 10:56 GMT
why you can not set value in your bindingsource row directly?
tomse - 24 Oct 2006 11:52 GMT
Thanks for reply,
could You give an example, do You know what's wrong with my way of
filling TextBox.Text in form constructor?
What bothers me most, is that I can fill bound TexBox from keyboard on
runtime, and can't do this programmatically after binding it to
dataset.
Greetings

Alterling napisal(a):
> why you can not set value in your bindingsource row directly?
tomse - 24 Oct 2006 11:52 GMT
Thanks for reply,
could You give an example, do You know what's wrong with my way of
filling TextBox.Text in form constructor?
What bothers me most, is that I can fill bound TexBox from keyboard on
runtime, and can't do this programmatically after binding it to
dataset.
Greetings

Alterling napisal(a):
> why you can not set value in your bindingsource row directly?
Alterling - 25 Oct 2006 09:47 GMT
> could You give an example
(1) small databind example: BindTestForm is a Form with ListBox
listBox1, TextBox textBox1 and Button button1, listBox1.DataSource is
set to collection of MyData {string Message {} public int Id{get;set;}}
Id is value member, Message is display member
on button click I want set current position listBox1 to item which Id
in textBox1.Text and modify this item

CurrencyManager cm;
public BindTestForm(){
....
col = new MyDataCollection();
....
this.listBox1.DataSource = col;
cm = (CurrencyManager)this.BindingContext[col];
}

private void button1_Click(object sender, System.EventArgs e) {
cm.Position = Convert.ToInt32(this.textBox1.Text);
MyData data = cm.Current as MyData;
data.Message += "*";
cm.Refresh();
}

You see - there is no direct manipulation with listBox1

(2) Look at DataTable.RowChanging event - when row is being added to
your table you receive this event with (DataRowAction.Add, <new row> )

> You know what's wrong with my way of filling TextBox.Text in form constructor?
When TextBox.Text was binded to some datasource any attempts to modify
this property is absolutely wrong. No matter, in form constructor or in
any other method. You should modify your datasource - table, collection
or whatever unstead.

> What bothers me most, is that I can fill bound TexBox from keyboard on
> runtime, and can't do this programmatically after binding it to
Thats correct.
Bart Mermuys - 26 Oct 2006 21:28 GMT
Hi,

> Thanks for reply,
> could You give an example, do You know what's wrong with my way of
> filling TextBox.Text in form constructor?
> What bothers me most, is that I can fill bound TexBox from keyboard on
> runtime, and can't do this programmatically after binding it to
> dataset.

You can't do it in the Form constructor, because DataBinding kicks in after
the Form Handle is created (erasing your value), it should work if you do it
inside Form_Load instead.

But i consider it better if you can set a default value on your DataSource,
either DataColumn.DefaultValue or handle DataTable.TableNewRow (NET2.0).

HTH,
Greetings

> Greetings
>
> Alterling napisal(a):
>> why you can not set value in your bindingsource row directly?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.