Groups > Borland > Delphi winforms controls > Re: DataBinding problem




DataBinding problem

DataBinding problem
Tue, 18 Jul 2006 20:46:32 +010
I have a datagrid that is bound to a list of objects (with only 1 object in 
the list).

If I edit the Name column of the object in the grid the value is not updated 
until I leave the cell.  I need to ensure that all changes are applied 
before the form closes so this is what I tried in the Form.Closing event

procedure TWinForm1.TWinForm1_Closing(sender: System.Object; e: 
System.ComponentModel.CancelEventArgs);
var
  Control: System.Windows.Forms.Control;
  BC: System.Windows.Forms.BindingManagerBase;
begin
  MessageBox.Show(ACountry.Name);
  for Control in Controls do
  begin
    BC := BindingContext[Control];
    BC.EndCurrentEdit;
  end;
  MessageBox.Show(ACountry.Name);

ACountry is a reference to the only object in the list, but both 
MessageBox.Show commands display the original value.  When I reopen the form 
I see the new value I typed has been accepted.

Can anyone tell me how to apply pending data changes immediately?

Pete

Post Reply
Re: DataBinding problem
Mon, 24 Jul 2006 15:16:21 +010
"Peter Morris [Droopy eyes software]"
<pete@NO_droopyeyes_SPAM.com> a écrit 
dans le message de news: 44bd3a9a@newsgroups.borland.com...

|I have a datagrid that is bound to a list of objects (with only 1 object in
| the list).
|
| If I edit the Name column of the object in the grid the value is not 
updated
| until I leave the cell.  I need to ensure that all changes are applied
| before the form closes so this is what I tried in the Form.Closing event
|
| procedure TWinForm1.TWinForm1_Closing(sender: System.Object; e:
| System.ComponentModel.CancelEventArgs);
| var
|  Control: System.Windows.Forms.Control;
|  BC: System.Windows.Forms.BindingManagerBase;
| begin
|  MessageBox.Show(ACountry.Name);
|  for Control in Controls do
|  begin
|    BC := BindingContext[Control];
|    BC.EndCurrentEdit;
|  end;
|  MessageBox.Show(ACountry.Name);
|
| ACountry is a reference to the only object in the list, but both
| MessageBox.Show commands display the original value.  When I reopen the 
form
| I see the new value I typed has been accepted.
|
| Can anyone tell me how to apply pending data changes immediately?

In order to use BindingContext[...].EndCurrentEdit, your classes must 
implement IEditableObject.

Joanna

-- 
Joanna Carter [TeamB]
Consultant Software Engineer 

Post Reply
about | contact