Format event in DataBinding 2.0

G

Guest

I created a DataSource for a Web Service.
Then drag&Drop the text boxes for the return values onto the forms designer.
BindingSource is created everything OK.

Then I want to format the output of one of the text boxes.
Here is my VB.NET code to wire up an event handler:

'get the Binding object for this textbox and setup the event
handler:
Dim bind1 As Binding
bind1 = TitleTextBox.DataBindings.Item(0)
AddHandler bind1.Format, AddressOf OnTitleTextBoxFormat

The event handler is not called the first time when displaying a value of
the datasource. It works fine the 2nd, 3rd ... times, just the initial
display is wrong.

Imho the Format event should be fired too when the control gets an initial
output.

What would be the correct event to wire up?

thanks herbert
 
G

Guest

Hi,

Just a thought, but is the call to add the handler made BEFORE filling the
table the first time ? If not, the Format event will indeed be called
whenever you modify the data, but not the first time that table is filled.

Regards,

Luc Morin
 
G

Guest

Hi Lukky,

this is what I thought. However
1) How do I find out?
2) Isn't Form_Load supposed to be the first place to execute user-defined
code? At least this is what the books say.
So where should I get to the event beforehand? Mingle with the
designer-generated code?
Is there another way than the Format event where I can modify the bound
output ?


regards herbert
 
G

Guest

Lukky,

you're right! I found it:
I have to bind the DataBindingSource to the underlying data AFTER the event
handler is wired up.


Dim bind1 As Binding
bind1 = TitleTextBox.DataBindings.Item(0)
AddHandler bind1.Format, AddressOf OnTitleTextBoxFormat
ResultElementsBindingSource.DataSource = r.resultElements 'bind to result
from Web Service

Thank you, herbert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top