ok
Hello,
This example illustrates how to implement a custom WinPropertyEditor that contains ListBoxControl and operates the ImmediatePostData property correctly.
We have created a descendant of the WinPropertyEditor class and overridden the CreateControlCore method in the following manner:
[C#]protectedoverrideobjectCreateControlCore(){ControlBindingProperty="SelectedItem";listBox=newListBoxControl();listBox.ValueMember=Model.LookupProperty;if(Model.ImmediatePostData)listBox.SelectedIndexChanged+=(s,args)=>listBox.DataBindings["SelectedItem"].WriteValue();listBox.Items.Clear();listBox.DataSource=View.ObjectSpace.CreateCollection(Model.ModelMember.Type);returnlistBox;}
[VB.NET]ProtectedOverridesFunction CreateControlCore() AsObject ControlBindingProperty = "SelectedItem" listBox = New ListBoxControl() listBox.ValueMember = Model.LookupPropertyIf Model.ImmediatePostData ThenAddHandler listBox.SelectedIndexChanged, Sub(s, args) listBox.DataBindings("SelectedItem").WriteValue()EndIf listBox.Items.Clear() listBox.DataSource = View.ObjectSpace.CreateCollection(Model.ModelMember.Type)Return listBoxEndFunction
The ListBoxControl as a default ListBox does not contain the SelectedItemChanged event. That is why data is not updated immediately when we bind to SelectedItem and the ImmediatePostData property is set to True.
To avoid this behavior, we send notifications from the SelectedIndexChanged event as follows:
[C#]listBox.SelectedIndexChanged+=(s,args)=>listBox.DataBindings["SelectedItem"].WriteValue();
Moreover, this editor supports the LookupProperty from the model.[VB.NET]AddHandler listBox.SelectedIndexChanged, Sub(s, args) listBox.DataBindings("SelectedItem").WriteValue()