Groups | Blog | Home
all groups > dotnet windows forms databinding > november 2006 >

dotnet windows forms databinding : Controls bound to an empty datasource



Huber Peter
11/29/2006 6:13:16 PM
hello

when I enter data into a bound control, but the datasource has no items, the
data is not saved anywhere and lost. How can I avoid someone can enter some
data into an bound control, what is not positioned to an vaild current field
in the datasource.

thnaks

Bart Mermuys
11/30/2006 11:21:24 PM
Hi,

[quoted text, click to view]

* If you have a BindingSource then attach an eventhandler to
BindingSource.PositionChanged, when Position is -1 then disable the Controls
otherwise enable them, eg. :

bindingSource.PositionChanged += new
EventHandler(bindingSource_PositionChanged);

private void bindingSource_PositionChanged( object sender, EventArgs e )
{
bool enabled = (bindingSource.Position != - 1);
textBox1.Enabled = enabled;
textBox2.Enabled = enabled;
}

* If you can put your Controls inside a Panel or GroupBox then you only need
to disable the Panel/GroupBox.

* If you don't have a BindingSource, then you can use the PositionChanged
event and Position property on the CurrencyManager which you can get from
the BindingContext.


HTH,
Greetings

[quoted text, click to view]

Jerry H.
12/1/2006 6:39:58 AM
Thank you for this information! This is EXACTLY the same issue I was
faced with, so this will help me in a number of ways!

[quoted text, click to view]
AddThis Social Bookmark Button