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?
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?