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 / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

problem with propertymanager ( textbox bound to dataset )

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Piotrekk - 24 Feb 2008 13:48 GMT
Hi

I have problem with propertymanager in my code. PositionChanged event
is not even raised. When i increase position, the value remains the
same - as a result textbox.Text value remains also unchanged.
How to solve these problems? I have tried to google but couldn't find
a solution.

ps - dataSet11 is typed dataset and is properly filled.

       private void Form1_Load(object sender, EventArgs e)
       {
           employeesTableAdapter1.Fill(dataSet11.Employees);

           tb = new TextBox();
           this.Controls.Add(tb);
           tb.Location = new Point(50, 50);
           tb.DataBindings.Add("Text", dataSet11.Employees,
"Lastname");

           pm = (PropertyManager)this.BindingContext[tb];
           pm.PositionChanged += new
EventHandler(pm_PositionChanged);

       }

       void pm_PositionChanged(object sender, EventArgs e)
       {

       }

       private void button1_Click(object sender, EventArgs e)
       {
           pm.Position += 1;
       }

Kind Regards
Marc Gravell - 24 Feb 2008 20:06 GMT
> I have problem with propertymanager in my code. PositionChanged event
> is not even raised.

2 problems in the code; one "possible" and one "definite"; starting
with the latter:

> pm = (PropertyManager)this.BindingContext[tb];

Here you are using "tb" as the data-source; to get the same currency-
manager you must bind to the same *data* - i.e.
this.BindingContext[dataSet11.Employees];

The second /possible/ issue is that the binding-context can actually
change during init; strictly speaking you would have to look at the
[On]BindingContextChanged override/event, otherwise it could a: error
(null value) or b: have a completely different binding-context
(unlikely, but theoretically possible).

However! If I can offer a simpler solution - use a BindingSource as an
intermediary?

           BindingSource bs = new BindingSource();
           bs.DataSource = dataSet11.Employees;
           bs.PositionChanged += pm_PositionChanged;
           tb.DataBindings.Add("Text", bs, "Lastname");

You can also use a BindingSource from the IDE designer.

Marc
Piotrekk - 24 Feb 2008 20:45 GMT
Thank you for your answer. But when is PropertyManager /
CurrencyManager really usefull then?
PK
Marc Gravell - 24 Feb 2008 20:58 GMT
> But when is PropertyManager / CurrencyManager
Well, one typical case would be when you are writing a data-bound
control, such as a grid (or indeed, textbox); since you are now the
*consumer* of the bound data, you can only use the more abstract forms
that BindingContext gives you - specifically the concrete
BindingManagerBase subclasses: CurrencyManager if you are expecting a
list (i.e. a grid/list control), or PropertyManager if you expect a
single item at a time (i.e. TextBox etc).

There's nothing to stop you from using these as the *caller*, but
you'd still need to use it correctly ([On]BindingContextChanged etc) -
but in short you are making your life harder than necessary. As the
caller, you can get away with using BindingSource (or similar) to make
things simple.

Marc
Piotrekk - 25 Feb 2008 10:10 GMT
I guess I will stay with BindingSource for simplicity ( Since am quite
new to ADO.NET ) . Thank you.

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.