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

dotnet windows forms databinding : Setting delegates for Binding.Format and Binding.Parse events?


Rick Mogstad
7/10/2006 1:23:43 PM
The BindingComplete event will only get called if a certain parameter is set
to true (the constructor with the 4th parameter as a boolean is the one).
That said, it will fire a LOT, so its not a good place.

I would put it right after I actually added the databindings for the grid.
If they are happening automatically, you should be able to do it after the
InitializeComponent call and they should be there, I would think.

-Rick

"David Veeneman" <davidv@nospam.com (domain is my last name)> wrote in
message news:%23DpIalFpGHA.3584@TK2MSFTNGP03.phx.gbl...
[quoted text, click to view]

David Veeneman
7/10/2006 2:45:23 PM
How do I set delegates for the Format and Parse events of design-time
bindings in .NET 2.0?

I have a grid that is data-bound to a custom object through a binding source
control:

dataGridView1 ---> bindingSource1 ---> WidgetList

WidgetList is a List<WidgetItem>. WidgetItem has two properties, Date and
Text.

I need to do some custom formatting in the grid's Date column, so I need to
declare delegates to handle the Format and Parse events for the 'Date' data
binding. Here's the code that sets the delegates to handle the events:

dataGridView1.DataBindings["Date"].Format += new
ConvertEventHandler(Date_Format);
dataGridView1.DataBindings["Date"].Parse += new
ConvertEventHandler(Date_Parse);

My question is: Where do I put this code?

First, I tried putting it in the constructor, then in the Form_Load handler.
The binding hadn't been created yet, so the code threw a null object
exception in both places.

Then, I tried putting the code in a bindingSource1_BindingComplete handler,
but that handler never got called by my code.

At this point, I'm scratching my head. Where should the delegate
declarations go? Thanks in advance.

--
David Veeneman
Foresight Systems

AddThis Social Bookmark Button